hi.
Pls give me the code to export data from datagrid or dataset into Excel in a simply way
regards
fazy
hi.
Pls give me the code to export data from datagrid or dataset into Excel in a simply way
regards
fazy
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Apr 26, 2009, 7:14 PM EDT
Export to Excel is one of the most common functionality required in ASP.NET pages. Users can download the data from the DataGrid into an Excel spreadsheet for offline verification and/or computation.
This article describes how to Export an ASP.Net 2.0 GridView to Excel.
In this version of the article, we will include the handling the Hyperlink columns in the GridView export to Excel and also re-factor our original logic to use more general features of Reflection.
In this article we will take the contents of our GridView control and spill it into an Excel spreadsheet using this wrapper mechanism.
Mahesh ChandRank #1 · 393.3K reputationPosted Apr 26, 2009, 7:14 PM EDT
Pero15 reputationPosted Mar 28, 2010, 11:43 PM EDT
with GemBox.Spreadsheet C# Excel library you can easily export DataSet to Excel.
See code snippet below:
// 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");