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

Free Support Forum - aspose.com

Reading cell value strings as they appear in Excel

I have a .xlsx (Excel 2007) file with numbers in some of the cells.
I want to retrieve the values as Strings via Java, but I can’t figure out how.
For instance, a field defined as a “Number with 2 decimal places” in Excel comes up as a Double in the Aspose.Cells Java API.

If the value in the cell is “34256346.00” in Excel, the Java API gives me a Double and I can’t tell how many decimal places were displayed in Excel.

Is there a way to retrieve the String value of a cell exactly as Excel displays it?


Well, you may utilize Cell.getStringValue() method for your need.

Here is the sample code which works fine for me, I utilzed a template excel file (attached):


// Create a new workbook.
Workbook wb = new Workbook();
// Create a worksheet object and obtain the first sheet.
Worksheet sheet = wb.getWorksheets().getSheet(0);
Cells cells = sheet.getCells();
Cell cell = cells.getCell("F14");
System.out.println(cell.getStringValue()); // Displays 32256346.00 ..........OK
cell = cells.getCell("F16");
System.out.println(cell.getStringValue()); // Displays 2352.00.........OK
cell = cells.getCell("F18");
System.out.println(cell.getStringValue()); // Displays 3334.87.........OK


catch(Exception ee)


Thank you.

That works great!
I think I had assumed getStringValue() should only be called on String values, much like getDoubleValue() should be called on Double values. But in fact, getStringValue() produces the same output as Excel displays.

Thanks for the help.