我尝试使用 Apache POI 将数字转换为欧洲货币样式
HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#.###,#0"));
例如我有数字 2400 和 2.4
我想要的是 2400,00 和 2,40 。 但是 POI 给了我 2400,0 和 2,40。 当我尝试将其更改为
currencyCellStyle.setDataFormat(cf.getFormat("#.###,00"));
我得到结果 2400,00 和 2,400。 这也不是我想要的。
是否有可能使两个值都正确?
致谢和问候
最佳答案
最后 Gagravarr 给出了正确的提示来解决这个问题。
最终的解决方案是:
HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#,##0.00\\ _€"));
解决方案是在手动创建 excel 文件后出现的。 然后通过 Apache Poi 读取它并 用
提取格式字符串 cell.getCellStyle().getDataFormatString()
结果是#,##0.00\_€
所以我在上面的代码片段中使用了这种格式,它给出了正确的结果。
谢谢
关于java - Apache POI 货币数据格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13838495/