如何货币类型设置为POI列 [英] How to set currency type to a column in POI

查看:320
本文介绍了如何货币类型设置为POI列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Java中使用POI转换列货币型XSSFWorkbook?

How do I convert a column to currency type in XSSFWorkbook using poi in java ?

下面是code我用:

DataFormat datafrmt = wbAll.createDataFormat();
cellStyle.setDataFormat(datafrmt.getFormat("$#,##0.00")); 

但设置数据格式我试图打开Excel工作表,并检查了列的格式它显示自定义的类型,但我需要的列是一个货币类型之后。我怎样才能做到这一点?

But after setting the data format I tried opening the Excel sheet and checked the format of the column it shows custom type but I need the column to be a currency type. How can I achieve this?

推荐答案

我会建议你使用的 BuiltinFormats 货币。这一次似乎是你要找的 7的人,$#,## 0.00);($#,## 0.00)。

I would suggest you use one of the BuiltinFormats for currency. This one seems to be the one you're looking for 7, "$#,##0.00);($#,##0.00)".

如何检查<一href=\"http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java\"相对=nofollow>阿帕奇表明通过在他们的演示制作 XSSFCellStyle 地图做。看完之后,我想你是唯一缺少这行code为您格式化工作。

Check how Apache suggests doing it by making a Map of XSSFCellStyle in their demo. After reading it, I think you are only missing this line of code for you format to work.

XSSFCellStyle style3 = wb.createCellStyle();
style3.setAlignment(XSSFCellStyle.ALIGN_RIGHT);  // THIS LINE HERE!
style3.setDataFormat(fmt.getFormat("$#,##0.00"));
styles.put("currency", style3);`

要使用 BuiltinFormats 的,而是采用了 XSSFDataFormat 例如,您可以直接设置短通缉格式, 喜欢这个
style3.setDataFormat((短)7);

To use the BuiltinFormats, instead of using a XSSFDataFormat instance, you directly set the short of the wanted format, like this style3.setDataFormat((short) 7);

这篇关于如何货币类型设置为POI列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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