Hi,
I found that FireFox adds a ".XLS" to your file name if you create an excel file and give it to the user via MemoryStream. In the FireFox download prompt if you choose "Save As" it works as expected. However, if you choose "Open" it adds ".XLS" to your file name.
I found a way to get it to work and thought I'd share in case someone else ran into this. According to this website: https://gullele.com/firefox-adds-xls-extension-when-downloading-excel-files-from-problem/ you need to set MIME type differently. I tried it and it worked for Firefox, Chrome and IE.
Sample code below:
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
// create new workbook
IWorkbook workbook = application.Workbooks.Create();
IWorksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].ColumnWidth = 25.86;
//string contentType = "Application/msexcel"; - when contentType is "Application/msexcel" firefox adds ".XLS" to the file name when opening
string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // this works correctly in each browser that I tried.
workbook.Version = ExcelVersion.Excel2016;
string fileName = "ScoreCard.xlsx";
try
{
MemoryStream ms = new MemoryStream();
workbook.SaveAs(ms);
ms.Position = 0;
workbook.Close();
excelEngine.Dispose();
return File(ms, contentType, fileName);
} catch
{
return View();
}
Thanks,
Chris