POI Appending .0 while reading numeric data from excel

十年热恋 提交于 2019-12-01 04:48:33
Gagravarr

This is virtually identical to a number of other questions here, such as returning decimal instead of string (POI jar)

The answer is the same as the one I gave here:

POI is giving you the exact value that Excel has stored in the File. Generally, if you write a number in an Excel cell, Excel will store that as a number with formatting. POI provides support to do that formatting for you if you want it (most people don't - they want the numbers as numbers so they can use them)

The class you're looking for is DataFormatter. Your code would be something like

 DataFormatter fmt = new DataFormatter();
 for (Row r : sheet) {
    for (Cell c : r) {
       CellReference cr = new CellRefence(c);
       System.out.println("Cell " + cr.formatAsString() + " is " + 
                          fmt.formatCellValue(c) );
    }
 }

Hi my solution was just to put the symbol:

'

in front of every number. Then the number is processed as text.

After you do that you would see little green triangle and warning:

For me this is not a problem, because it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!