Apache poi - Thousand separator

2019-06-22 14:54发布

问题:

Do you know how can I set the thousand sepator and have a value formatted like this? 403.000

I'm using apache-poi 3.8 with Java. I googled it a lot but I didn't find an answer. I can't use a string value because my formulas are not evaluated correctly in this way. Any help? thanks!

I've tried something like this:

cellStyle.setDataFormat(creationHelper.createDataFormat().getFormat("#.##0")); 

but it doesn't work..

回答1:

You can do this:

 final HSSFCell dataCell = dataRow.createCell(1);
 dataCell.getCellStyle().setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
 dataCell.setCellValue(123456);

You'll have a cell with the number display like this: 123.456 The thousand separator depends of the locale and perhaps of the language of excel.



回答2:

Ok, I found it: the format must be this: "#,##0"