Excel cannot open the file. XLSX

hi,

I am having a problem returning an Excel File generated through Aspose cells. The file is created and saved successfully but when I try to open it I get the error:

“Excel cannot open the file ‘test.xlsx’ because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file”

Here is my code. Please help:

wk = new Workbook();
sheet = wk.Worksheets[0];
sheet.Cells.ImportCustomObjects(await _masterDataUpload.GetContractforMasterData(ProjectId, 
                       BlueprintId, 1), 7, 0, new ImportTableOptions { });                                                                      
return File(wk.SaveToStream().ToArray(), "application/vnd.openxmlformats- 
                       officedocument.spreadsheetml.sheet", "test.xlsx");   

The awaited call is to a SQL datastore and returns a generic List of objects.

Please help

@Ian_Baldwin,

This is the culprit part/line:
wk.SaveToStream().ToArray()

Please note, SaveToStream method saves the file in XLS (older) file format, you cannot save to XLSX file format using this method. To save to newer Excel (XLSX) file format, you may use Workbook.Save (Stream, SaveOptions) overloaded method. So, you should correct/update your code segment accordingly.