繁体   English   中英

使用Apache POI将Excel单元格格式化为Dollar,其中机器货币不是美元

[英]Formatting Excel cell as Dollar with Apache POI where the machine currency is not dollar

我使用Java和Apache POI格式化Excel工作表。

我想格式化一个单元格作为美元。

使用基本Excel货币格式与Apache POI的建议,我得到的是单元格格式为谢克尔(恰好是我的机器的默认货币)

如何将单元格格式化为美元,即使我的机器的默认货币不是美元。

我使用的代码如下

CellStyle dollarStyle=wb.createCellStyle();
dollarStyle.setDataFormat(7);
CellUtil.getCell(myRow, 1).setCellStyle(dollarStyle);

数字7来自http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html

这是有效的(这是G​​agravarr的建议)

CellStyle dollarStyle=wb.createCellStyle();
DataFormat df = wb.createDataFormat();
dollarStyle.setDataFormat(df.getFormat("$#,#0.00"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM