Setting Time in Excel using POI

后端 未结 3 1246
谎友^
谎友^ 2021-02-09 18:40

I am trying to create an Excel Work sheet using POI api in Java. In that Excel Work Sheet I want to have a cell with TIME alone. By setting this we can include the cell in summa

3条回答
  •  忘了有多久
    2021-02-09 19:10

    I have used the following code to generate the time cell, in Excel using POI. And I am able to use the cell in

            XSSFRow row2 = sheet.createRow(25);
            XSSFCell cell1 = row2.createCell(4);
            XSSFCell cell2 = row2.createCell(5);
    
            CellStyle style = wb.createCellStyle();
            DataFormat df = wb.createDataFormat();
            style.setDataFormat(df.getFormat("[h]:mm:ss;@"));
    
            cell1.setCellFormula("TIME(0,15,00)"); // 00:15:00
            cell1.setCellType(Cell.CELL_TYPE_FORMULA);
            cell1.setCellStyle(style);
            evaluator.evaluateFormulaCell(cell1);
    
            cell2.setCellFormula("TIME(0,30,00)"); //00:30:00
            cell2.setCellType(Cell.CELL_TYPE_FORMULA);
            evaluator.evaluateFormulaCell(cell2);
            cell2.setCellStyle(style);
    

提交回复
热议问题