setCellType(HSSFCELL.CELL_TYPE_NUMERIC) is not working in apache poi

半世苍凉 提交于 2019-12-12 21:09:08

问题


SetCellType(HSSFCELL.CELL_TYPE_NUMERIC) is not working in apache poi. Anyone have used this feature of POI in JAVA?

When I created XLS file using POI and cell contains integer value and I set cell type as numeric at that time that cell reflects some other integer value. Example: Using JAVA program and poi utility, I am putting in Cell A1 value "5". Now this cell contains Integer value but by default cell type is CELL_TYPE_STRING. So this cell gives me error and asked me to convert this cell to Number. But using program when I will set this cell type as CELL_TYPE_NUMERIC at that time it does not give me error in XLS file but it shows me different value.

Anyone has faced such issue? If yes then is there any solution for this. I stuck up with this one.

Please ask me if you need some more clarification.

Thanks in advance.


回答1:


Since you are using XSSF not HSSF, use cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC) instead of setCellType(HSSFCELL.CELL_TYPE_NUMERIC).




回答2:


** Give a Integer value instead of a String Value.**

HSSFCell cell = row.createCell(col);
cell.setCellStyle(style);
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
if(value!=null)
    cell.setCellValue(Integer.parseInt(value));


来源:https://stackoverflow.com/questions/27840258/setcelltypehssfcell-cell-type-numeric-is-not-working-in-apache-poi

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