Apache POI : How to format numeric cell values

前端 未结 4 592
青春惊慌失措
青春惊慌失措 2020-12-19 21:28

I am using Apache POI 3.9 for XLS/XLSX file processing.

In the XLS sheet, there is a column with numeric value like \"3000053406\".

When I read it with POI w

4条回答
  •  不思量自难忘°
    2020-12-19 22:13

    Creating a BigDecimal with the double value from the numeric cell and then using the

    BigDecimal.toPlainString()

    function to convert it to a plain string and then storing it back to the same cell after erasing the value solved the whole problem of exponential representation of numeric values.

    The below code solved the issue for me.

        Double dnum = cellContent.getNumericCellValue();
        BigDecimal bd = new BigDecimal(dnum);
        System.out.println(bd.toPlainString());
        cellContent.setBlank();
        cellContent.setCellValue(bd.toPlainString());
        System.out.println(cellContent.getStringCellValue());
    

提交回复
热议问题