Home » excel » java – Apache POI: Excel changes my format string

java – Apache POI: Excel changes my format string

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have this code:

 HSSFCellStyle styleCurrency = workbook.createCellStyle();;
 CreationHelper ch = workbook.getCreationHelper();
 String format="# #";
 DataFormat dataFormat=ch.createDataFormat();
 styleCurrency.setDataFormat(dataFormat.getFormat(format));

But when i check that cell in Excel’s Format Dialogue it shows : #\# (It adds slash). Why?

I’m using Excel 2003.

How to&Answers:

I found the ansewer by myself (as usual no help). To dysplay # # in Excel’s Format Dialogue, add comma between #’s instead of white space. So #,# becames # #. Also, 0,00 becames 000 in Format Dialogue. To fix it add dot instead of comma, so 0.00 = 0,00. Interesting why noone faced the same problem before as there’s no info in internet.