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

21,254

Solution 1

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

Solution 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));
Share:
21,254
Nishith Shah
Author by

Nishith Shah

Updated on July 09, 2022

Comments

  • Nishith Shah
    Nishith Shah almost 2 years

    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.