Save Dataset As Excel File C#
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.
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 PropertyDescriptor
s for the columns, or use classes with actual properties (eg, an anonymous type) instead of DataTable
.