I am using Apache POI HSSF to create an Excel spreadsheet from my Java web application.
I need a cell formatted as "Number" with two decimal points. (My values ββin Java are BigDecimals, but I can convert them to doubles, no problem.) I use this code:
CellStyle numericStyle = wb.createCellStyle(); numericStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); // output in this new style... row.createCell(cellnum).setCellValue(((BigDecimal)value).doubleValue()); row.getCell(cellnum).setCellStyle(numericStyle);
The problem is that although this works, Excel still shows my cells as General . They should appear as a Number . As a result, for example, 0 is displayed as 0, but should be 0.00, which will happen if the format was correct ( Number ).
I see that it is generated as General , because I can right-click on a cell and then select "Format Cells" to see what it is now.
Thanks for any help. Apache POI HSSF must be set to "Number". Any advice is appreciated.
source share