What is the best way to save xls to xlsx in aspose? Will it cause any issue?

Hi Team,

I am getting different formats for Date field in cell.getStringValue() while fetching same formatted data from xls and xlsx.

Let’s say my Excel contains mm/dd/yyyy

Xls returns -> mm-dd-yyyy
Xlsx return -> mm/dd/yyyy

Anyway within my code I am trying to save workbook after users uploads so I cam across such below options.

wb.save(“abc.xls”, new XlsSaveOptions(SaveFormat.XLSX));

wb.save(“abc.xls”, SaveFormat.XLSX);

Also please note with this also file remains abc.xls but gives correct output same as Excel.
Now Xls returns -> mm/dd/yyyy which is expected.

Please note I don’t want to change the extension xls should remain xls and xlsx should remain xlsx and below code does that

wb.save(“abc.xls”, new XlsSaveOptions(SaveFormat.XLSX));
wb.save(“abc.xls”, SaveFormat.XLSX);

C_Test.zip (19.7 KB)

Just wanted to check that what is difference between above two ? What is best to use? Will there be any issue while saving format as xlsx?

For xls, there may be regional settings data in the template file and the formatted result will be determined by that data. For xlsx there is no such kind of data so the formatted result depends on the default region of current thread. To get the expected formatted result, you need no change for the file format, please just specify the expected region/Locale for the workbook before getting cell’s string values:

wb.getSettings().setLocale(…);

@johnson.shi

Thanks. It worked for me.

@nemish.doshi,

Good to know that specifying your regional settings/locale to your default(expected) locale works for your needs.