Apache poi - Thousand separator

时光毁灭记忆、已成空白 提交于 2019-12-23 09:48:28

问题


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"



来源:https://stackoverflow.com/questions/14876548/apache-poi-thousand-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!