Hi,
I am generating a Excel file and then sending it through a web page to open or download. The file gets generated, but we receive an error with the content(see attachment). The Excel message says that it needs to repair it. When I click Yes, The file opens properly for me. However, our client, gets the same message, but cannot open the file.
Below is the code that I am using to generate and downlaod the file;
Can you please let me know if I should do anything differently ?
Thanks,
John
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
....,.....
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "report.xlsx"));
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.CacheControl = "no-cache";
workbook.SaveAs("report.xlsx", ExcelSaveType.SaveAsXLS, HttpContext.Current.Response, ExcelDownloadType.Open, ExcelHttpContentType.Excel2016);
workbook.Close();
excelEngine.Dispose();
Attachment:
ProblemWithContent_52f77faf.zip