Save Dataset As Excel File C#

Posted on
Save Dataset As Excel File C# Rating: 3,2/5 646 reviews

I'm trying create a excel file based in a Dataset.

This is my really simple code.

Oct 20, 2014  It says to create a file called Excel.xsl, paste code from that page into it and save the file in the same directory as your. This article explains how to export the DataSet into Excel using C# excel interop API. Using the code Before starting code make sure add excel interop reference (Microsoft.Office.Interop.Excel) from add references in visual studio. I'm trying create a excel file based in a Dataset. This is my really simple code. Using (var dataSet = new DataSet()) { var table = dataSet.Tables.Add('TotalUsers').

but my excel file result in this:

I have to pass to Export a iqueryble. I think is there my mistake.

AFetterAFetter

1 Answer

You're seeing the actual properties defined in DataRow, not the columns of your table.

You need to change your Export() method to check for & consume IListProvider to get custom PropertyDescriptors for the columns, or use classes with actual properties (eg, an anonymous type) instead of DataTable.

SLaksSLaks

Not the answer you're looking for? Browse other questions tagged c#exceldataset or ask your own question.