|Summary:||After setting a cell to String type, the result of getStringCellValue for some certain format cells is not right|
|Component:||POI Overall||Assignee:||POI Developers List <dev>|
Description jwang 2013-12-12 21:33:16 UTC
Please try the following to replicate the bug. ...... Cell cell = row.getCell(0); cell.setCellType(Cell.CELL_TYPE_STRING); 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". Thanks!
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.