Bug 55875

Summary: After setting a cell to String type, the result of getStringCellValue for some certain format cells is not right
Product: POI Reporter: jwang
Component: POI OverallAssignee: POI Developers List <dev>
Severity: critical    
Priority: P2    
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

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.