Write Double value in numeric cell with specific format in Apache Poi 3.7

前端 未结 3 1792
广开言路
广开言路 2021-01-02 03:14

I need to write a Double value in a numeric cell using a specific format, i mean, the generated xls must have numeric cells containing Double values like, for example: 8,1.

3条回答
  •  春和景丽
    2021-01-02 03:46

    I tried this working fine...

    HSSFCellStyle cellStyle = wb.createCellStyle();
    HSSFDataFormat hssfDataFormat = wb.createDataFormat(); 
    String cellVal = "2500";
    cellStyle.setDataFormat(hssfDataFormat.getFormat("#,##0.000"));
    newCell.setCellStyle(cellStyle);
    newCell.setCellValue(new Double(cellVal));
    newCell.setCellType(Cell.CELL_TYPE_NUMERIC);
    

    The output is a numeric value with desired format: 2,500.000

提交回复
热议问题