Search code examples
javaapache-poistylesheetlibreoffice

Currency Format Apache POI


I need to set format for BRL coin into my sheet. I'm using Apache POI for set currency style with code below:

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

But when i open my xlsx file into LibreOffice (i'm a linux user ), my cells are not formatted. Checking the cell contains a quote ' at beggin of cell value and when retired this quote, my cell value is formatted correctly. Prints of my sheet after and before. Please any sugestions?

Edit: My method that create and setValue into cell ( passing as parameter the style above):

 public XSSFCell criarCelula(int indice, String conteudo, XSSFRow linha, XSSFCellStyle estilo) { 
   XSSFCell celula = linha.createCell(indice); 
   celula.setCellValue(conteudo); 
   celula.setCellStyle(estilo); 
   return celula; 
} 

Solution

  • I got it with sugestion of Axel Ritcher. Using my content into double type instead of string.

    Double conteudo;
    celula.setCellValue(conteudo);