We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Evaluating upgrade Aspose 8.7.1.0 from 7.5.0.1 (breaking changes)

Hi guys, we're evaluating upgrading cells to stay current but we ran into a breaking change that we depend on.

In 7.5.0.1 we rely on the "getter" for SafeOptions.SaveFormat to determine the mime type we need to send back to the response stream.

I know you changed SaveOptions but for some reason the getter on SafeFormat is no longer working the same way.

We get back "default" when I expected to get back xlsm. We use a reporting framework to open a file and then rely on aspose.cells later to tell us what the correct format was. We don't hold onto the original extension.

Here's how we do it with 7.5.0.

var sf = Xls.SaveOptions.SaveFormat.ToString();

returns "Xlsm" if we opened a macro file

With 8.7.1.0

var ff = Xls.FileFormat.ToString();

returns "Default" if we open a macro file.

We were depending on cells internal version of saveformat. This now looks write-only. How can we get what cells is going to save as?

thanks a ton Marty at Cigna

Hi Marty,


Thank you for contacting Aspose support.

Please note, Aspose.Cells.Workbook’s default format is XLS so if you are loading an XLS file or creating a spreadsheet from scratch using the default constructor of Workbook class then its format would be XLS. Moreover, the Workbook.SaveOptions property has been removed from the public API since the release of 8.7.0. Please check this document for Removed APIs.

That said, based on the latest APIs, I would suggest you to use the Workbook.FileFormat property to detect the format of the Workbook. In case of an XLS file (regardless of the macros inside it), the property will return Default. You an include an additional check using the Workbook.HasMacro property to detect if the loaded spreadsheet has macros in it and decide the resultant spreadsheet format accordingly.

C#

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(dir + “sample.xls”);
Console.WriteLine(workbook.HasMacro);
Console.WriteLine(workbook.FileFormat.ToString());

ok thanks! I'll try that has macro method.

I was just surprised when loading a file.xlsm, the file format coming back was .xlsx? That seemed weird but you are correct the HasMacro is true.

So, I guess we can use HasMacro to decide what we want but ideally we wanted the same format as the extension we passed in.

Let me know if you have additional ideas? We can work around this knowing what you mentioned.

thanks again for fast reply - say hi to team

Hi again,

MartyOne:

I was just surprised when loading a file.xlsm, the file format coming back was .xlsx? That seemed weird but you are correct the HasMacro is true.


I am not able to observe the said problem on my side. I have tested many samples and I am getting the correct FileFormat for XLSM files. Could you please share your sample here for further investigation?

MartyOne:

Let me know if you have additional ideas? We can work around this knowing what you mentioned.


Please note, Aspose.Cells APIs also provide FileFormatUtil.DetectFileFormat method in order to facilitate the format detection of a spreadsheet. This feature does not require to load the spreadsheet in an instance of Workbook to know its format because it was designed to detect the load format. However, I think the solution shared in my previous post should suffice.

thanks Barbar. I can't send you anything huge but here's what you might check - just in case.

a. We open a workbook with .xlsm , Xls = new Workbook (filename.xlsm);

b. We get the saveformat and specify before saving, and specify .xlsm

c. we save to stream using file format - xlsm

d. after save, we watch the value in debugger go from xlsm to xlsx.

Xls.Save(stream, sf);

Hoping this is due to workbook and/or stream save operations

thanks

Marty

Hi Marty,


Thank you for writing back.

I have tested the scenario while using the following piece of code and I am still not able to see any problem with a sample XLSM of my own (attached).

C#

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(dir + “book1.xlsm”);
Console.WriteLine(workbook.FileFormat.ToString());
MemoryStream stream_2 = new MemoryStream();
workbook.Save(stream_2, SaveFormat.Xlsm);
stream_2.Position = 0;
Console.WriteLine(FileFormatUtil.DetectFileFormat(stream_2).FileFormatType);

That said, are you facing the said issue with all of your sample XLSM files or some particular spreadsheet exhibit this behaviour? Moreover, Could you please give a try to the latest version (8.7.1.3 attached) that I am currently using for all tests?

In case the problem persists with latest version as well, please provide us an executable sample application along with the input spreadsheet for thorough investigation.