In my java class, I declare the cell as:
HSSFCell cell = null;
And I use this cell in many places to create a cell and set values, styles. How:
cell = row.createCell(1);
cell.setCellValue("1234.00");
setCellStyle(currency, cell, workbook);
cell = row.createCell(2);
setCellValue("2445.00");
Now, surprisingly, the first cell data format is applied to the 2nd cell. Does anyone have an idea? I expect that the style of the second cell will not be. And the style of the 1st cell should be with the data format used by the setCellStyle () method. But in fact, I get both cell values โโwith the data format used by the setCellStyle () method.
setCellStyle ():
public void setCellStyle(String currency, HSSFCell cell, HSSFWorkbook workbook){
HSSFCellStyle cellStyle = cell.getCellStyle();
HSSFDataFormat dataFormat = workbook.createDataFormat();
if("GBP".equalsIgnoreCase(currency)){
cellStyle.setDataFormat(dataFormat.getFormat("[$ยฃ-809]#,##0_);[Red]([$ยฃ-809]#,##0)"));
}else (){
cellStyle.setDataFormat(dataFormat.getFormat("$#,##0_);[Red]($#,##0)"));
}
}
source
share