I am using Apache POI to render few reports in Excel. My requirements are,
- Display the dates in Spanish format, the cell type in excel should be date.
- Display the decimal amount/price/currency value in Spanish format (e.g.: 12,23 or 1.454,23), the cell type in excel should be number even though it has ',' in the value and should be able to apply the number functions on those cells.
When I try setting the values using the following code with Spanish locale in the system,
CellStyle style = workBook.createCellStyle();
style.setDataFormat(workBook.createDataFormat().getFormat("##0.00%"));
cell.setCellStyle(style);
cell.setCellValue(new Double(23.45).doubleValue());
It displays the value as 23.45% (not respecting the system locale) and allows the number functions. To fix it, if I change the format to "##0,00", then the values are not displayed properly and it is not considering the cell as a number column, hence the number functions are not working. So, I either have to convert it to text and set the value (where I will lose the ability of using the number functions in the cells) or use the '.' format to display the number (which is not the requirement).
Questions:
- How can I set the Spanish format number/currency and still make the cell type accept the number functions (even with ',' in the numbers)?
- Is there a way to force this format in a cell without setting the value as text?
- Is there a way to force the excel file locale to Spanish locale, so that wherever it is opened, it displays the values in Spanish format?
- Using the above code, I generated the excel file with the standard format (##0.00) and expected it to change the format (to ##0,00) when the system's locale is changed, but it did not.
Any help would be greatly appreciated. Thanks.
23.45
set in an Excel cell and formatted using percent format##0.00%
must show either2345.00%
or2345,00%
dependent on the systems decimal separator. In Excel 1 == 100%. So0.2345
will be23.45%
in Excel. So I suspect the problem you are facing is elsewhere in code you are not showing. – Axel Richter