0
votes

I am using apache poi-3.9 to create Excel (xls) worksheets with some measurement data, which are supposed to be displayed with units within the cell. Units are mbar, mm/sec, and (°) degrees. For mbar and mm/sec everything works perfectly fine, but with degrees formatting gets lost. Microsoft Excel complains with the following error message: "File error. Some number formats may have been lost." Here is my code:

final HSSFWorkbook hssfWorkbook = new HSSFWorkbook();

final HSSFCellStyle cellStyleMbar = hssfWorkbook.createCellStyle(); final HSSFCellStyle cellStyleDegree = hssfWorkbook.createCellStyle();

cellStyleMbar.setDataFormat(dataFormat.getFormat("0 \"mbar\"")); cellStyleDegree.setDataFormat(dataFormat.getFormat("0.0 \"°C"));

Thank you for your ideas!

1

1 Answers

2
votes

The problem is probably that you don't close the quoted text in the format template.

Replace

dataFormat.getFormat("0.0 \"°C")

with

dataFormat.getFormat("0.0 \"°C\"")