Free Support Forum -

Unexpected results using Cell.getStringValue()


We are using Aspose.Cells for Java version 7.3.4. We are trying to read a value in an Excel spreadsheet from a cell that has formatting of type “General” by calling cell.getStringValue() on that Cell. Values in this cell are typically numeric, but alpha characters are allowed as well.

When numeric values of over 12 digits in length are entered in this cell, for example: 1234567890709, the value displayed in the cell is in E notation: 123457E+12. I assume Excel does this formatting by default in “General” type fields?

Our issue is, when we read the cell using cell.getStringValue(), we are expecting to get “1234567890709”, but instead we are getting the formatted value “123457E+12”.

Is this cell.getStringValue() behavior we are seeing as-designed? If so, what are our options (if any) for getting the un-formatted value?

Thank you.


Well, Aspose.Cells follows MS Excel standards, so if you can input the value “1234567890709” as general in MS Excel manually, the value would be converted to scientific notations i.e.
It is an expected behavior of Aspose. Cells. I think about your needs, you got to specify the numeric formatting, e.g. you may specify the custom formatting i.e. "0" and set the style, now when you read the value, it will give you your desired results, see the sample code with the attached template file for your reference:

Sample code:

Workbook wb = new Workbook("Book_getString.xlsx");
Worksheet sheet = wb.getWorksheets().get(0);
Style style = sheet.getCells().get("A1").getStyle();
System.out.println(sheet.getCells().get("A1").getStringValue()); // .... 1234567890709

Thank you.

Thanks for your quick response and for explaining why this is expected behavior!

I’ll see if we can take the approach of setting the cell Style when we read the Cell.


Thanks for your posting and using Aspose.

If you face any other issue, please feel free to post on our forums, we will be glad to assist you further.