Scott Hanselman

Exporting tabular data to Excel from ASP.NET

April 21, '03 Comments [5] Posted in Web Services | ASP.NET | XML
Sponsored By

There's a number of ways to "export" data to Excel from an ASP.NET site - some more elegant than others.

  • Gross: You can use ASP.NET to generate a CSV file of Mime Type text/plain or text/csv and write it back to the browser.
  • NOT Gross: You can use ASP.NET to generate an XML-SS (Excel XML Spreadsheet) document and write it back to the browser.
  • Really Easy but not Really XMLy: You can take advantage of the ASP.NET DataGrid's ability to generate HTML tables quickly and return the page with a Mime Type of application/vnd.ms-excel.  Here's a great example on how to create these reports
  • Easy but uses 3rd Party Control: Use ExcelWriter on the server side to create the Report.
  • Disgusting: Automate Excel on the ServerSideDon't do this for Pete's Sake.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Tuesday, April 22, 2003 7:03:17 AM UTC
OK, Scott, why do you find the XML approach "less gross"? It seems like the cleanest solution to me.
Tuesday, April 22, 2003 3:42:13 PM UTC
Oops...I meant to write NOT Gross.
Thursday, March 11, 2004 1:53:19 PM UTC
You say not to use automation. How am I supposed to create multiple worksheets and manipulate them? Automation seems to be the only way to do it and I have an application that needs to create a workbook and add three different worksheets from three different datasets. If you could explain how to do this without having to use automation and NOT using 3rd-party controls, I would appreciate it.

Thanks!
Ivan Samuelson
Thursday, June 03, 2004 3:27:32 AM UTC
How did you know that I need to do this? There must be a hole in my tin-foil hat again.

Seriously, I appreciate the post and will put it to good use.

Thanks.
Thursday, November 03, 2005 6:25:18 AM UTC
fdsfd
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.