for exporting DataGrid to Excel in Excel ASP.NET
application, I recommend you take a look at this Excel C#
It doesn't require Excel Automation
and API is pretty simple and intuitive:
var people = (DataTable)dataGrid.DataSource;
// Create excel file.
var ef = new ExcelFile();
var ws = ef.Worksheets.Add("DataSheet");
ws.InsertDataTable(people, "A1", true);
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename="
// With XLSX it is a bit more complicated as MS Packaging API
// can't write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
var ms = new MemoryStream();