Tuesday, 15 April 2014

java - POI - Handling data in HH:MM:SS.sss Format -



java - POI - Handling data in HH:MM:SS.sss Format -

i working in project have info in hh:mm:ss.sss format, have generate study in excel/spreadsheet. using poi generate excel file, facing next problems:

if set info in string format i.e cell.setcellvalue("02:45:6.7"); impossible utilize excel formulas such average, sum, etc. if format cell in [h]:mm:ss.000;@ i.e. cs.setdataformat(df.getformat("[h]:mm:ss.000;@")) not works, string.

hssfcellstyle cs = hssfworkbook.createcellstyle(); hssfdataformat df = hssfworkbook.createdataformat(); cs.setdataformat(df.getformat("[h]:mm:ss.000;@"));

excel not have function(as per knowledge) takes info in hh:mm:ss.sss format, tried using 'time(hh,mm,ss)' , formatting cell [h]:mm:ss.000;@ not shows value after decimal point replaces 000 i.e time(02,45,6.7) displayed 02:45:6.000

i tried making changes in poi source code, tried steps per in question http://stackoverflow.com/a/10306350/2513084 still not work. generated file says - some formulae or name of file contains built-in functions kingsoft spreadsheet not support, , recalculation of these formulas or name may cause wrong results. microsoft office not able open file gave error file error: info may have been lost.

i not working poi long time, far recall ... dates nil else numbers (milliseconds). cell type defined date/numeric cell.

the actual visual representation of cell defined elsewhere.

some old code of mine (probably not latest poi version has statement):

hssfcell cell = newrow.createcell(column); date date = new date(some_date_value); cell.setcelltype(hssfcell.cell_type_numeric); cell.setcellvalue(date);

you can set cell style (display format) as:

cell.setcellstyle(style);

so dig style part ... , how set (sorry have no working illustration of part). maybe work code ... not setting value numeric string.

java excel apache-poi

No comments:

Post a Comment