I'm generating an EEPlus .xlsx file that the user can download after clicking a button. It won't open on my Win8 machine with LibreOffice 4.4.1.2, but it will open on my coworkers Win8 machine using Excel 2013.
I get an error saying the file is corrupt and needs to be repaired, and when I try to repair it, it says it's unable to. My coworker also gets this error but is able to repair it and view the file.
Here's the relevant code for the creation of the downloadable version:
MemoryStream ms = DataTableToExcelXlsx(dt, "Report");
ms.Position = 0;
ms.WriteTo(Response.OutputStream);
Response.ContentType="application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=DataTable.xlsx");
Response.StatusCode = 200;
Now the weird part is that I'm also generating an xlsx file that is attached to an email, and it opens just fine. Neither me nor my coworker receive the error when opening the file attached to to the email.
Relevant code for the creation of the email attached version:
MemoryStream ms = DataTableToExcelXlsx(dtReportData, sReportTitle);
ms.Position = 0;
MailMessage mail = new MailMessage("you@yourcompany.com", sReportEmails);
using (SmtpClient client = new SmtpClient())
{
mail.Subject = "Mixer - Test Scheduler Task Execute.";
mail.Body = string.Format("The following report is executing. ReportSettings Id: {0}", reportSettingsId);
mail.Attachments.Add(new Attachment(ms, sReportTitle + ".xlsx", "application/vnd.ms-excel"));
client.Send(mail);
}
I've also tried using the vnd.ms-excel
MIME type for the downloadable version and that didn't work, so I'm at a loss as to why this is happening.