货币格式Apache POI

问题描述 投票:0回答:1

我需要在工作表中设置BRL硬币的格式。我正在使用Apache POI通过以下代码设置货币样式:

XSSFCellStyle style = xssfWorkbook.createCellStyle();
style.setDataFormat(cf.getFormat("R$#,##0.00;\\R$-#,##0.00"));

但是当我将xlsx文件打开到LibreOffice(我是Linux用户)时,我的单元格未格式化。检查单元格在单元格值开头处是否包含引号',并且在停用该引号时,我的单元格值格式正确。我的工作表afterbefore的打印件。请任何建议?

编辑:我的方法,该方法创建并设置Value到单元格中(作为参数传递上面的样式):

 public XSSFCell criarCelula(int indice, String conteudo, XSSFRow linha, XSSFCellStyle estilo) { 
   XSSFCell celula = linha.createCell(indice); 
   celula.setCellValue(conteudo); 
   celula.setCellStyle(estilo); 
   return celula; 
} 
java apache-poi stylesheet libreoffice
1个回答
0
投票

我是Axel Ritcher的建议。使用我的内容成双精度类型而不是字符串。

Double conteudo;
celula.setCellValue(conteudo);
© www.soinside.com 2019 - 2024. All rights reserved.