Back in February I wrote
All spreadsheet applications (Excel, Calc etc.) understand semicolon separated files natively, so everyone can use this method - you don't even have to use Excel for it to work.
public static void ExportToSpreadsheet(DataTable table, string name)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
foreach (DataColumn column in table.Columns)
{
context.Response.Write(column.ColumnName + ";");
}
context.Response.Write(Environment.NewLine);
foreach (DataRow row in table.Rows)
{
for (int i = 0; i
Then just call this method and pass the DataTable and the filename as parameters.
ExportToSpreadsheet(table, "products");
The method is static so you can use it anywhere in a web application. Put it on a page, a HTTP Handler, add it to the App_Code folder or stick it in a separate assembly. As long as you call it from a web application it will work.
Tag:
Add to Del.icio.us | Digg | Reddit | Furl
Bookmark murdok:
Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.
http://www.madskristensen.dk/
ASP.NET: Export a DataTable to Excel
0 views
Comments (0)
Please sign in to leave a comment.





No comments yet. Be the first to comment!