https://issues.apache.org/bugzilla/show_bug.cgi?id=46156
Josh Micich <[EMAIL PROTECTED]> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEEDINFO
--- Comment #4 from Josh Micich <[EMAIL PROTECTED]> 2008-11-05 23:42:33 PST ---
(In reply to comment #2)
> ... What if POI
> can give support to get the Formula RESULT directly from excel? ...
As it turns out, Excel *does* cache the results of calculations for each
formula cell (In POI the equivalent data is mapped to
FormulaRecord.field_4_value).
You can access numeric formula results with HSSFCell.getNumericCellValue()
For example:
InputStream is = new FileInputStream("sample.xls");
HSSFWorkbook wb = new HSSFWorkbook(is);
HSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
System.out.println("Value is " + cell.getNumericCellValue());
I made a workbook 'sample.xls' in Excel with the formula "=0.5+0.1" in
Sheet1!A1. With that spreadsheet, the above code produced the following
output:
Value is 0.060000000000000005
It appears that internally Excel has the same rounding issue, so getting "the
Formula RESULT directly from excel" is not going to help us here.
-- -- -- --
I still believe that the solution to this problem involves intelligent rounding
during number to text conversion. For example:
double messyResult = 0.05+0.01;
String resultText = ExcelNumberToTextConverter.render(messyResult); // *
double roundedResult = Double.parseDouble(resultText);
System.out.println(roundedResult);
*ExcelNumberToTextConverter would be a new POI class.
If you disagree, can you explain why a solution like this won't do what you
need, and/or suggest a specific alternative?
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]