Bug 55875 - After setting a cell to String type, the result of getStringCellValue for some certain format cells is not right
Summary: After setting a cell to String type, the result of getStringCellValue for som...
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2013-12-12 21:33 UTC by jwang
Modified: 2013-12-12 23:35 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description jwang 2013-12-12 21:33:16 UTC
Please try the following to replicate the bug. 

    Cell cell = row.getCell(0);
    String s = cell.getStringCellValue();

With MS excel 2007, when the cell value is like, "123.567", and its cell format is "General" in excel, the value of String s will be, "123.56699999999999". But if the cell value is like "12.4567" or "12345.7", the value of String s will be the same, "12.4567" or "12345.7".

Comment 1 Nick Burch 2013-12-12 23:35:32 UTC
Calling cell.setCellType(Cell.CELL_TYPE_STRING) will change the low level type of the cell, as stored in the file. POI will try to convert the type in a basic way for you, which is what you're seeing.

If you want full control over how the number becomes a string, fetch the number, apply your own rules, then set the resulting string.

If you just want to get a string holding the number as formatted in Excel, you'll need to use DataFormatter.