我正在使用Java和Apache POI格式化Excel工作表。
我想将一个单元格格式化为美元。
使用带有Apache POI的Basic Excel货币格式的建议,我得到的是单元格的格式设置为shekels(恰好是计算机的默认货币)
即使我的计算机的默认货币不是美元,如何将单元格格式化为美元。
我正在使用的代码如下
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
这有效(这是Gagravarr的建议)
CellStyle dollarStyle=wb.createCellStyle();
DataFormat df = wb.createDataFormat();
dollarStyle.setDataFormat(df.getFormat("$#,#0.00"));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句