Recover incorrectly saved file

I - by accident - saved an XLSB file in XLSX file format. When I try to open from either Excel or Aspose.Cells it says it can’t open it because it contains Macro enabled content.


Any ideas on how I can handle this?

Hi,


Thanks for your posting and using Aspose.Cells.

Please provide us your Excel file so that we could test your issue at our end and help you out.

Unfortunately I cannot, it is a customer file which I cannot share.


Question: Is there a way that I can change a file saved as XSLX to XLSM when it does not open in Aspose.Cells?

Are there any options that would allow Aspose to load the file it saved as XLSX?

Hi,


Thanks for your posting and using Aspose.Cells.

I - by accident - saved an XLSB file in XLSX file format.

How did you save XLSB file to XLSX format? Did you save it via Microsoft Excel? Or did you save it with Aspose.Cells?

In any case, how did you lose the original XLSB file?

Suppose I have a file named A.xlsb and I open it in Microsoft Excel and save it back as B.xlsx.

Now I should have two files A.xlsb (original one) and B.xlsx (my re-saved file). So, there is no need to recover because I already have A.xlsb with me.

Similarly, if I load A.xlsb in Aspose.Cells and save it back as B.xlsx, then even if B.xlsx is corrupt, I should have original A.xlsb with me.

Question: Is there a way that I can change a file saved as XSLX to XLSM when it does not open in Aspose.Cells?

Are there any options that would allow Aspose to load the file it saved as XLSX?

Aspose.Cells can load XLS, XLSX, XLSM, XLS files if they are not already corrupt. But if a file is already corrupt, then Aspose.Cells will throw exception and even if it loaded it successfully, it will not be reliable.

Thank you. We dug deeper and because the XLSB file had macros we did lose information. There is corruption, but independent of this. I am create a new post for that since it is independent of this.

Hi,


Thanks for using Aspose.Cells.

XLSM is a superset of XLSX. It is actually an XLSX (Macro-Enabled) format.

Please check if your workbook has macros using Workbook.HasMacro property. If it is true, then you must save it in XLSM format. Because Macros file cannot be saved in XLSX format because it might make them corrupt.

But if it does not have macros, then you can either save it to XLSX or XLSM format.

Please check the sample XLSB file which has Macros attached with this post. And see this code and its comments. It will help you how to deal with macros file correctly.

C#
Workbook wb = new Workbook(“sampleMacro.xlsb”);

//First check if this Excel file has macros
if(wb.HasMacro == true)
{
//Since it has macros so save it in Xlsm format. Xlsx will not be OK here.
wb.Save(“outSampleMacro.xlsm”);
}
else
{
//Since it does not have macros so save it in Xlsx format. But Xlsm will also be OK here
wb.Save(“outSampleMacro.xlsx”);

}