I've met some problem with generating Excel files using org.apache.poi.ss.usermodel utils
: Values above 1000 have dot (.) as a decimal separator and values below 1000 have comma (,) as a decimal separator.
I've trying a lot of different ways put BigDecimal values into 'Cell' but each time the result is the same, regardless of setting up cell type on CELL_TYPE_NUMERIC
or CELL_TYPE_STRING
or doing something like this:
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("###0,00"));
cell.setCellStyle(cellStyle);
I managed to get rid of this problem by unifying the decimal separator - I am taking a String value of this BigDecimal, replacing all dots into commas and done! But when opening Excel all the fields are marked up and there is a warning which says that value in this cell is formatted as a text. I can set up it as a number and then making diferent mathematical operations on them. But I'd like to get generated Excel file with no warnings to resolve (and hence - cells set up as numbers to make mathematical operations on them), with BigDecimal
values with comma as a decimal separator.
I create my sheet and cells as follows:
Workbook workbook = new SXSSFWorkbook();
Sheet sheet = workbook.createSheet("mySheet);
int rowNum = 1;
List<MyRecord> records = (...);
for (MyRecord record : records) {
Row row = sheet.createRow(rowNum++);
int cellNum = 0;
for (String attribute : attributeList) {
String cellData = cellData(record, attribute);
if(cellData != null) {
Cell cell = row.createCell(cellNum);
cell.setCellValue(cellData);
}
cellNum++;
}
}