Make the web work for you

John's insights into the what's going on on the internet, internet news and opportunities.

Thursday, 13 March 2008

Exporting data to excel using VB.NET/ASP.NET

This post is going to be a little code heavy, but I do like to share a useful function every so often. Here I've picked up on the good work done at http://www.dotnetspider.com/qa/Question1653.aspx and taken it a little step further to simplify it use.

This consists three functions. The first of which you would call from your ASP.NET code if you have a DataTable that you would like to be available to users as to Save or Open in Excel:

The vb.net export code

Here's the code: Feel free to ask any questions find faults or heap praise upon it! :) Export-to-excel-from-vb.net.txt.

Read on for how to use.

Exporting to Excel from a datatable

This is the simpler one. Just call the sub DownloadDataTable pass in a DataTable and a Filename to save as.

Exporting to Excel from a datagrid

This isn't actually much more complex to use to be honest... Just call the sub DownloadDataGrid, but this time pass in a DataGrid and a Filename to save as.

2 Comments:

  • At 14 July 2008 11:20 , Anonymous Anonymous said...

    thanks for ur code, i hv tried to run this code inside my application but its for runat server entry..can u guide me about html view code

     
  • At 14 July 2008 11:41 , Blogger John said...

    Hey Anonymous,
    Would be happy to try to help - feel free to drop me an email with your question and I'll publish any solution here too.
    Thanks for reading!
    John

     

Post a Comment

Links to this post:

Create a Link

<< Home