Displaying data in Excel sheet from DataGrid
This article shows that how we can show the data of a DataGrid in an excel sheet.
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Displaying data in Excel sheet from DataGrid


PeroPosted Sep 3, 2010, 2:52 AM EDT
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, 6:33 PM EST
Hi dis site is really good... I tried workin the above code.. it really worked..