java - Applying specific cell data format using POI -


i need apply specific data format cell.

xssfcellstyle cellstyle  = workbook.createcellstyle();           xssfdataformat format = workbook.createdataformat(); cellstyle.setdataformat(format.getformat("m/d/yy h:mm")); datacell.setcelltype(1); //string datacell.setcellstyle(cellstyle); 

the data being written problem format applied only when open excel sheet (in excel application), click inside cell data.
, pressing enter key. format applied.

how can apply format without clicking on every cell?

your problem you're setting cell string. part, cell formatting rules apply numeric cells. don't apply string cells, don't formatted (as they're formatted string!)

xssfcellstyle cellstyle  = workbook.createcellstyle();           xssfdataformat format = workbook.createdataformat(); cellstyle.setdataformat(format.getformat("m/d/yy h:mm")); datacell.setcellstyle(cellstyle);  // set cell type not needed, setcellvalue datacell.setcelltype(cell.cell_type_numeric); // set date value (2012-06-05 08:50) datacell.setcellvalue(new date(1338878999635)); 

when open in excel, ought have expected


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -