Save to CSV converting to scientific notation

Hi

I’m converting xlsx files to csv using the standard workbook.save() method.
When my xlsx contains a large integer with the format “auto” the resulting csv contains the value converted to scientific notation.
For example, when converting the attached:
123456789123 becomes 1.23457E+11

How can I stop this happening?

Thanks

Hi,

Thanks for your posting and using Aspose.Cells.

If you write 123456789123 to a file and change its extension to csv and then open it in Microsoft Excel, you will find that it is shown in scientific notation.

So, this is not a bug of Aspose.Cells but a correct behavior of both Aspose.Cells and MS-Excel.

If you want to get rid of it, then append apostrophe ’ before the number.

i.e

123456789123

Hi,

Thanks for using Aspose.Cells.

As a workaround, you can first convert your number into string and then save your workbook into csv format.

Please see the following sample code that explains this method. I have attached the source excel file used in this code and the output csv file generated by it for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(0);


Cell cell = worksheet.getCells().get(“A1”);


cell.putValue(cell.getStringValueWithoutFormat());


workbook.save(“output.csv”);


Thanks for the workaround and the quick response!

Hi,


Good to know that your issue is sorted out now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.