workbook,SaveAs() downloads corrupt file

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

1 Reply

SS Sridhar Sukumar Syncfusion Team June 15, 2017 12:07 PM UTC

Hi John, 
 
Thank you for contacting Syncfusion support. 
 

We are unable to reproduce the issue with shared information. We have shared a simple sample for your reference which can be downloaded from the following location.  

 

Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/XLSIO_ASPNET-159010494.zip 

 

Kindly modify the sample to reproduce the issue and share us the modified issue reproducing sample which will be helpful for us to give you a prompt solution at the earliest. 

  

Regards, 

Sridhar. 



SIGN IN To post a reply.
Loader.
Up arrow icon