Apache POI 货币数据格式 [英] Apache POI Currency Data Format

查看:79
本文介绍了Apache POI 货币数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 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?

谢谢和问候

推荐答案

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

谢谢

这篇关于Apache POI 货币数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆