java - Format number with thousands separator in Excel using Apache POI -
i want format number cells, comma thousands separator. example:
12 -> 12 1200 -> 1,200 12000 -> 12,000 12000000 -> 12,000,000 120000000 -> 120,000,000 i have following code. should use formatstr? there easy way? or have detect number of zeros in order produce #,###,###?
string formatstr = ""; hssfcellstyle style = workbook.createcellstyle(); hssfdataformat format = workbook.createdataformat(); style.setdataformat(format.getformat(formatstr)); cell.setcellstyle(style); cell.setcelltype(hssfcell.cell_type_numeric); keep in mind i'm dealing numbers. cell type numeric, not string.
update

just #,### or #,##0 should sufficient. excel interprets having thousands separators every 3 digits (not before last three, infer expecting).

in spirit of teaching man fish, how can find out yourself:
format number, 0 decimal places, 1000 separator:

click ok, re-open number format dialog , go custom. have @ formatting code ("type"). says #,##0, me gives exact same result #,###.

Comments
Post a Comment