Create Report in Excel from SQL Server Data
I want to create report in excel using C# .Net from SQL Server Database. If user click a button, then data should be exported to excel from specific table and excel should be displayed in the browser.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Mahesh ChandRank #1 · 393K pointsPosted Aug 7, 2008, 2:08 PM EDT
There are two steps to do this and this is the fastest way to do it.
1. You need to get data from the database. Fill it out in a DataGrid, which is not visible on the page.
2. Export DataGrid to Excel.
Here is an article, that gets data from the database, fills in a DataGrid and export it to Excel.
http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx
In your code, you have to set DataGrid.Visible = false; to hide your DataGrid.