Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache poi - Thousand separator

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..

like image 857
Vargan Avatar asked Feb 14 '13 14:02

Vargan


2 Answers

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.

like image 118
F. Geraerts Avatar answered Oct 31 '22 17:10

F. Geraerts


Answering my own question for everyone else who might have the same issue.

found it: the format must be: "#,##0"

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

like image 25
Vargan Avatar answered Oct 31 '22 16:10

Vargan