jason jason - 7 months ago 98
ASP.NET (C#) Question

Excel cannot open Gembox Spreadsheet file

I have this code to generate an Excel file and download it:

SpreadsheetInfo.SetLicense("mycode");
ExcelFile myExcelFile = new ExcelFile();
ExcelWorksheet ws = myExcelFile.Worksheets.Add("Page 1");
myExcelFile.Save(Response, "asd.xlsx"); //this is for download


When I download the Excel file, it says:


Either file type or file extension is not valid so Excel cannot open
this file. Confirm that file is not broken or file extension matches
file type.


I'm trying to solve this for hours but I couldn't find a solution. I use same code other places and it works, but it doesn't work at this part of my project. Can you tell me what I should do? Thanks.

Answer Source

Try to save the fire as an xls-file instead of an xlsx-file. I'm guessing that the default is xls. Excel can get confused if the file extension is wrong.