java - Get currency applied to an Excel Cell using POI -
i have written java program read excel file cell-by-cell using poi api. setting of currency done explicitly using ms excel - "format cell" option.
however, there way in can recognize currency has been applied cell using poi?
so far, have tried using getcellstyle().getdataformat() , returns unique number. however, problem is based on cell style, , can change change in cell formatting(font, size, etc.).
i tried this:
if(cell.cell_type_numeric) { system.out.println("value in excel cell:: " + cell.getnumericcellvalue()); short styletype = cell.getcellstyle().getdataformat(); system.out.println("style (currency):: " + styletype); if(styletype == <some unique number>) //want unique number { system.out.println("currency applied cell:: " + <currency name>); } } so, either unique number identifies currency name or if currency name directly, best.
you can identify built in format id looking @ org.apache.poi.ss.usermodel.builtinformats class, or format string using same class
string dataformatstring = builtinformats.getbuiltinformat(cell.getcellstyle().getdataformat()); or can currency format using getdataformatstring() method cellstyle
string dataformatstring = cell.getcellstyle().getdataformatstring(); update:
looking @ hssfdataformat class
international formats
since version 2003 excel has supported international formats. these denoted prefix "[$-xxx]" (where xxx 1-7 digit hexadecimal number). see microsoft article creating international number formats more details on these codes.
for currency format prefix [$c-xxx] c currency symbol , xxx hexadecimal value of locale identifier (lcid) appropriate language , location, can parse data format string currency.
an example, currency "eur € spanish (spain)" data format string #.##0 [$€-c0a];-#.##0 [$€-c0a] can translate [$€-c0a] in "currency eur - spanish", "usd $ english (ee. uu.)" data format string [$$-409]#.##0;-[$$-409]#.##0 can translate [$$-409] in "currency usd - english (u.s.)"... etc
hope helps.
Comments
Post a Comment