The text of this article is not in this database — only its details are. Read it on the old site: Displaying data in Excel sheet from DataGrid
3 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Displaying data in Excel sheet from DataGrid
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
PeroPosted Sep 3, 2010, 6:52 AM
This method downloads HTML, not Excel files. If you want to produce real Excel files from your Excel ASP.NET projects, I recommend you take a look at this Excel .NET library. Here is a sample Excel C# code how to export DataGrid to Excel: // Get DataTable that DataGrid is bound to. var dataTable = (DataTable)dataGrid.DataSource; // Create new ExcelFile. var ef = new ExcelFile(); // Add new worksheet to the file. var ws = ef.Worksheets.Add(dataTable.TableName); // Insert the data from DataTable to the worksheet starting at cell "A1". ws.InsertDataTable(dataTable, "A1", true); // Stream file to browser. Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls"); ef.SaveXls(Response.OutputStream); Response.End();
Sivaranjani ThanakaranPosted Feb 10, 2009, 11:33 PM
Hi dis site is really good... I tried workin the above code.. it really worked..