karmah Posted December 4, 2003 Posted December 4, 2003 Hello everyone! Is it possible to export a Dataset to a Excel file? I can't use an ASP.net solution. Any idea??? Thanks Quote
Voca Posted December 8, 2003 Posted December 8, 2003 There is a quite good article including source code on accessing Excel from .net using VB.net. http://support.microsoft.com/default.aspx?scid=kb;en-us;301982 Simply move through your dataset and write each value into your sheet. Nonperformant solution: use two For each-Loops (one for the rows, one for the columns). Don't know if it would work like that: take column from Dataset put it into column from Excel-sheet. Just try. Voca Quote
cikaPero Posted March 9, 2010 Posted March 9, 2010 Hi, well if you are looking for easy, fast and clean solution, I recommend this Excel VB.NET component. Here is a code snippet of DataSet to Excel export: // Create new ExcelFile. var ef = new ExcelFile(); // Imports all the tables from DataSet to new file. foreach (DataTable dataTable in dataSet.Tables) { // Add new worksheet to the file. var ws = ef.Worksheets.Add(dataTable.TableName); // Insert the data from DataTable to the worksheet starting at cell "A1". ws.InsertDataTable(dataTable, "A1", true); } // Save the file to XLS format. ef.SaveXls("DataSet.xls"); Quote
tfowler Posted March 12, 2010 Posted March 12, 2010 The simplest solution I use is just to save it as a delimited text file (tab, comma, whatever), and then Excel can import it. In addition, it is not limited to Excel. Todd Quote
Recommended Posts