Search code examples
apache-poistylesnumber-formatting

Set thousand separator Apache POI


I'm triying to format the number on my report with Apache poi but it is not working, I tried :

c.getCellStyle().setDataFormat(HSSFDataFormat.getBuiltinFormat("#.##0,00"));

and

c.getCellStyle().setDataFormat((short)BuiltinFormats.getBuiltinFormat("#.##0,00"));

But they are not working, I'd like to show it as 1.000,99 but it is showwing 1000,99

I've only found the custom option but not the numeric, is it possible to use it ?do you know how to do it work? enter image description here

Thanks


Solution

  • I got it. This is my solution :

       DataFormat format = workbook.createDataFormat();
        CellStyle style = workbook.createCellStyle();
        style.setDataFormat(format.getFormat("#,##0.00"));
    ...
        Cell c = row.createCell(cellDynamicNum);
        c.setCellStyle(style);