Apache POI货币数据格式 [英] Apache POI Currency Data Format
问题描述
我尝试使用Apache POI将数字转换为欧洲货币风格
I try to convert numbers into european currency style with Apache POI
HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#.###,#0"));
我有例如2400和2.4
I have for example the number 2400 and 2.4
我想要的是2400,00和2,40。
但是POI给了我2400,0和2,40。
当我尝试将其更改为
What I want is 2400,00 and 2,40 . But POI gives me 2400,0 and 2,40. When I try to change it to
currencyCellStyle.setDataFormat(cf.getFormat("#.###,00"));
我得到的结果是2400,00和2,400。
多数民众赞成也不是我想要的。
I get the result 2400,00 and 2,400. Thats also not what I want.
是否有可能让两个值都正确?
Is there a possibility to get both values correct?
Thx和Greetings
Thx and Greetings
推荐答案
最后,Gagravarr给出了解决这个问题的正确提示。
Finally Gagravarr gave the right tips to solve this question.
最终的解决方案是:
HSSFDataFormat cf = workbook.createDataFormat();
currencyCellStyle = workbook.createCellStyle();
currencyCellStyle.setDataFormat(cf.getFormat("#,##0.00\\ _€"));
手动创建excel文件后出现了解决方案。
然后由Apache Poi读取,
用
The solution came up after creating an excel file manually. Then read it in by Apache Poi and extracting the format string with
cell.getCellStyle().getDataFormatString()
结果是#,## 0.00 \ _€
The result was #,##0.00\ _€
所以我在上面的代码片段中使用了这种格式,它给出了正确的结果。
So I used this format in the upper code snippet, which gave the correct result.
Thx
这篇关于Apache POI货币数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!