Converting comments to an answer. Keeping comments as they might be easier to follow through
First of all, following format should be used for currencies
_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)
(this format is takes straight from excel so its working 100%).
Now that we have the format, lets have a look at the currency issue that has been encountered. The following code shows all currencies with their symbol/sign:
for (Currency c : Currency.getAvailableCurrencies()) {
System.out.println(c.getCurrencyCode() + " : " + c.getSymbol());
}
From this we can see, that only USD
has a "real" symbol, while all other currencies in that class only have their currency code as symbol. This seems to be the actual issue here. Using this code:
String format = "_(<ccy>* #,##0.00_);_(<ccy>* (#,##0.00);_(<ccy>* \\\"-\\\"??_);_(@_)";
style.setDataFormat(wb.createDataFormat().getFormat(format.replace("<ccy>", "€")));
we can see, that it does work with the actual symbols, but fails if the symbols are replaced by their currency codes. This caused OP to check excel and he found that excel itself offers a currency format for BGN
, but after all, apache-poi
is not excel.
This provided format will work with most currency as long as the proper symbol is provided. I checked a few currency symbold from this site and found that not all currency symbols are supported. Дин.
works while CHF
and RD$
both fail. This might be changed in the future.
Note that I tested it with apache-poi 3.15
. This might already work better in 3.17
_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)
– XtremeBaumerCurrency
format converted to a custom one. Should behave exactly the same – XtremeBaumer