Apache POI货币数据格式

Log*_*ith 6 java apache-poi

我尝试使用Apache POI将数字转换为欧洲货币风格

HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#.###,#0"));
Run Code Online (Sandbox Code Playgroud)

我有例如2400和2.4

我想要的是2400,00和2,40.但POI给了我2400,0和2,40.当我尝试将其更改为

currencyCellStyle.setDataFormat(cf.getFormat("#.###,00"));
Run Code Online (Sandbox Code Playgroud)

我得到的结果是2400,00和2,400.多数民众赞成也不是我想要的.

是否有可能使两个值都正确?

感谢和问候

Log*_*ith 11

最后,Gagravarr给出了解决这个问题的正确提示.

最终的解决方案是:

HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#,##0.00\\ _€"));
Run Code Online (Sandbox Code Playgroud)

手动创建excel文件后出现了解决方案.然后通过Apache Poi读取它并使用提取格式字符串

 cell.getCellStyle().getDataFormatString() 
Run Code Online (Sandbox Code Playgroud)

结果是#,## 0.00\_€

所以我在上面的代码片段中使用了这种格式,它给出了正确的结果.

谢谢