Hi. I am using the following code to try to export data to Excel from a standard ASP.net GridView but am getting the error in the attached image.
protected void btnExportExcel_Click(object sender, EventArgs e)
{
ExportExcel();
}
protected void ExportExcel()
{
//Initialize the Excel Engine
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Initialize GridView control
GridView gridView = this.GridView1;
//Initialize Application
IApplication application = excelEngine.Excel;
//Set default version for application.
application.DefaultVersion = ExcelVersion.Excel2013;
//Create a new workbook
IWorkbook workbook = application.Workbooks.Create(1);
//Accessing first worksheet in the workbook
IWorksheet worksheet = workbook.Worksheets[0];
//Import data from GridView control
worksheet.ImportGridView(gridView, 1, 1, true, true);
//Save the workbook to disk in xlsx format
workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.Open, ExcelHttpContentType.Excel2013);
}
}