Try the Gridview to Excel Export Tool


This is the code you must write, in your web page, to export data to an Excel 2003 spreadsheet.
   ' xml2003 declaration as the GEETEasyresponse2003
   Dim xml2003 As GEETMultiSheetClass.GEETEasyResponse2003 
   ' xml2003 instantiation - you pass User Name (this is just to create a distinguished file name) the calling Web Page, a
   ' Description and the SqlDatasource you want to export the data from

   ' you can either pass a SqlDatasource or a Dataview or an Objectdatasource

   xml2003 = New GEETMultiSheetClass.GEETEasyResponse2003(Me.User.Identity.Name, _
   Me.Page, Me.LbGridviewTitle.Text, Me.MySqlDataSource, Nothing) 

   ' xml2003 execution
   xml2003.Execute()

This is the code behind the export button to Excel 2007.

Protected Sub ButtonExcel2007_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonExcel2007.Click 
   ' xlsx2007 declaration as the GEETEasyResponse2007

   Dim xlsx2007 As GEETMultiSheetClass.GEETEasyResponse2007 
   ' CALL passing a dataview and Gridview
   ' by providing the Gridview, the tool will export from the Dataview only those columns which are visible
   ' and databound in the Gridview columns

   Dim DV As New System.Data.DataView DV = Me.MySqlDataSource.Select(DataSourceSelectArguments.Empty)
   xlsx2007 = New GEETMultiSheetClass.GEETEasyResponse2007(Me.User.Identity.Name, _
   Me.Page, Me.LbGridviewTitle.Text, DV,  Me.GridView1)

   xlsx2007.Execute()
End Sub

Try the Gridview to Excel Export Tool