货币格式 Apache POI
Currency Format Apache POI
我需要在 sheet 中设置巴西雷亚尔硬币的格式。我使用 Apache POI 设置货币样式,代码如下:
XSSFCellStyle style = xssfWorkbook.createCellStyle();
style.setDataFormat(cf.getFormat("R$#,##0.00;\R$-#,##0.00"));
但是当我在 LibreOffice 中打开我的 xlsx 文件时(我是 linux 用户),我的单元格没有格式化。检查单元格在单元格值的开头包含一个引号 ' 并且在停用此引号时,我的单元格值格式正确。我的 sheet after and before 的照片。请问有什么建议吗?
编辑:我在单元格中创建和设置值的方法 (
作为参数传递上面的样式):
public XSSFCell criarCelula(int indice, String conteudo, XSSFRow linha, XSSFCellStyle estilo) {
XSSFCell celula = linha.createCell(indice);
celula.setCellValue(conteudo);
celula.setCellStyle(estilo);
return celula;
}
我在 Axel Richter 的建议下得到了它。使用我的内容为双精度类型而不是字符串。
Double conteudo;
celula.setCellValue(conteudo);
我需要在 sheet 中设置巴西雷亚尔硬币的格式。我使用 Apache POI 设置货币样式,代码如下:
XSSFCellStyle style = xssfWorkbook.createCellStyle();
style.setDataFormat(cf.getFormat("R$#,##0.00;\R$-#,##0.00"));
但是当我在 LibreOffice 中打开我的 xlsx 文件时(我是 linux 用户),我的单元格没有格式化。检查单元格在单元格值的开头包含一个引号 ' 并且在停用此引号时,我的单元格值格式正确。我的 sheet after and before 的照片。请问有什么建议吗?
编辑:我在单元格中创建和设置值的方法 ( 作为参数传递上面的样式):
public XSSFCell criarCelula(int indice, String conteudo, XSSFRow linha, XSSFCellStyle estilo) {
XSSFCell celula = linha.createCell(indice);
celula.setCellValue(conteudo);
celula.setCellStyle(estilo);
return celula;
}
我在 Axel Richter 的建议下得到了它。使用我的内容为双精度类型而不是字符串。
Double conteudo;
celula.setCellValue(conteudo);