Dear all,
I would like to make sure if I am correct on the number formatting, when
reading from Excel with the HSSF libraries. I am reading an xls file,
created with Excel 2003, and wonder about the possibilities to extract
the numbers from a sheet.
Suppose a user enters a number like '3.1415' in a cell, which has a
number formatting with two decimals, there are several manners of state
of the number has within the file:
- the floating point number which Excel uses internally, could be
something like '3.14150000003'
- the formatted number, shown in Excel, '3.14'
- the original number, '3.1415'
Am I correct in saying, both the first two occurrences can be retrieved
using POI, with:
a) String value = cell.toString();
b) HSSFDataFormatter formatter = new HSSFDataFormatter();
String value = formatter.formatCellValue(cell);
c) HSSFDataFormatter formatter = new HSSFDataFormatter();
double tariffDoubleValue = cell.getNumericCellValue();
String value = formatter.formatRawCellContents(tariffDoubleValue, 0,
"#.####");
Using the last possibility, you need to make the assumption that all
numbers are entered using the format "#,####"
Am I correct in this approach, or is there a possibility to retrieve the
original entered number? Tried to find some an answers in the list
archive and api, but could not find it.
thanks & regards,
Frank