JavaGrot
JavaGrot

Reputation: 37

Format a cell to two decimal places POI

I am trying to format the cell to have two digits after the dot. But something is not working for me

row.getCell(updatedMDColumnIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(countValue);
    CellStyle style =  row.getSheet().getWorkbook().createCellStyle();
    style.setDataFormat(row.getSheet().getWorkbook().createDataFormat().getFormat("0.00"));
    row.setRowStyle(style);

Upvotes: 0

Views: 1142

Answers (1)

alexxarisis
alexxarisis

Reputation: 76

I think it is because you are trying to apply a CellStyle into a Row. Consider applying the style into a Cell object as in:

    Cell cell = ...// get the Cell you want.
    cell.setCellStyle(style);  // The style is the CellStyle you created.

Upvotes: 3

Related Questions