Here is an example of how we can export data of Grid View or other DataBound Controls to an excel file. I am using Grid View to Export data in this example but by modifying code you can also export data from Data List or Repeater control. Below are the some features of this example
•You can Display desired fields in Exported Excel Sheet, by default all the fields which are displayed in GridView were exported
•You can have Full control over formatting of data
•Youcan Replace Control like Hyperlink, dropdownlist, checkbox and other controls before exporting data to excel.
I am using following table named tbemp in my example. You can create this table in your database by using following script Copy Paste Following code in your .aspx page
Now add the following code in your Page_Load Event
Now copy paste Following code below your Page_Load Event
thanks..nice article.. but when exorting to excel it shows an error that the format is different..Actually it creates an biff file instead of xls file..please post how to export data to real xls file..
Again I find an new article about export data to Excel,I also know many libraries which can export data to Excel very easily. Why not try others and combine all the solutions together, I know that would be a huge task. However, from it both you and your readers can learn more. Here I can suggest you two solutions. You can see below link:
Spire.DataExport and Spire.Free DataExport: http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Program-Guide/How-to-Export-Datatable-to-Excel-through-DataGridView.html Spire.XLS: http://www.e-iceblue.com/Knowledgebase/Spire.XLS/Program-Guide/Data-Export-/Import-Export-Datatable-to-Excel-from-Database.html
I am really looking forward to your post.michelle.chang@e-iceblue.com
Easy stuff.. Try exporting to PDF using iTextSharp library.
The exported excel file is just an HTML file saved as excel.
thanks..nice article..
but when exorting to excel it shows an error that the format is different..Actually it creates an biff file instead of xls file..please post how to export data to real xls file..
Again I find an new article about export data to Excel,I also know many libraries which can export data to Excel very easily. Why not try others and combine all the solutions together, I know that would be a huge task. However, from it both you and your readers can learn more. Here I can suggest you two solutions. You can see below link:
Spire.DataExport and Spire.Free DataExport:
http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Program-Guide/How-to-Export-Datatable-to-Excel-through-DataGridView.html
Spire.XLS:
http://www.e-iceblue.com/Knowledgebase/Spire.XLS/Program-Guide/Data-Export-/Import-Export-Datatable-to-Excel-from-Database.html
I am really looking forward to your post.michelle.chang@e-iceblue.com
Export GridView data to Excel