9

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

Vargan
  • 1,277
  • 1
  • 11
  • 35
  • Try this: http://stackoverflow.com/questions/5335285/write-number-in-excel-cell-with-poi – Shane Feb 14 '13 at 14:19
  • @Shane, that question is related to decimals value, I need to have the sepator for thousand, so, if my value is 1000000, I want to show 1.000.000 – Vargan Feb 14 '13 at 14:23
  • How would you do that in Excel? And did you try asking POI to do it the same way that you would do in Excel? – Gagravarr Feb 14 '13 at 14:36

2 Answers2

9

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"));

Vargan
  • 1,277
  • 1
  • 11
  • 35
8

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.

F. Geraerts
  • 1,150
  • 17
  • 23