Still getting zzzyyy.xls is in a different format than specified by the file extension

Hi Guys,


Our client has asked us to make sure all our excel sheets that we generate are readable by Excel 2003 onwards. We are using this code to save out the spreadsheet,

public byte[] GetAsByteArray()
{
try
{
System.IO.MemoryStream myMemoryStream = new System.IO.MemoryStream();
contentGuide.Save(myMemoryStream, new XlsbSaveOptions(SaveFormat.Excel97To2003));

byte[] contentasByteArray = myMemoryStream.ToArray();

return contentasByteArray;
}
catch (Exception e)
{
throw new Exception (“Unable to convert the Aspose Workbook to a byte array for storage in DB”, e);
}
}

This is written to our database. When we write the file out and send it out, we are still getting the error, "The file you are trying to open, ‘FileName_7857386_120119.xls’, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

The client really wants us to get rid of this error message. What are we doing wrong? If I open this file and do Save As, I would have expected the “Save As Type” to be Excel 97-2003 but its actually set to Excel Binary Workbook (*.xlsb). Maybe this is a red herring but could it point to us saving it into the database incorrectly or out of the database?

Any ideas gratefully received

Kind regards

Mike



Hi,


Well, the culprit line is here:
System.IO.MemoryStream myMemoryStream = new System.IO.MemoryStream();
contentGuide.Save(myMemoryStream, new XlsbSaveOptions(SaveFormat.Excel97To2003));

it should be changed to:

contentGuide.Save(myMemoryStream, new XlsSaveOptions(SaveFormat.Excel97To2003));

Thanks Amjad,


Do I feel like a fool!

It’s been a long day and all that. I hang my head in developer shame! :slight_smile:

Thanks for spotting this

Mike

Hi,


No Problem, sometimes, it does happen, relax! :slight_smile:
Have a nice day!