java - Xlsx issue, cell.getCellStyle().getDataFormat() changing value after adding or removing date -


i using block of code cell.getcellstyle().getdataformat() . changes it's values after adding or removing content xlsx. should done in case?

enter image description here

first cell 21/01/2016 returns cell.getcellstyle().getdataformat() retuns 14 when add rows cell.getcellstyle().getdataformat() returns 165

if (dateutil.iscelldateformatted(cell)) {     double val = cell.getnumericcellvalue();     date date = dateutil.getjavadate(val);      string datefmt = null;     system.out.println(cell.getcellstyle().getdataformat());     xssfcellstyle style = (xssfcellstyle) cell.getcellstyle();     system.out.println("in int: "+style.getdataformat());      if (cell.getcellstyle().getdataformat() == 14) {          system.out.println("14");         datefmt = "dd/mm/yyyy";      } else if(cell.getcellstyle().getdataformat() == 165) {          system.out.println("165");         datefmt = "m/d/yy";     } else if(cell.getcellstyle().getdataformat() == 166) {         system.out.println("166");         datefmt = "d-mmm-yy";      } else if(cell.getcellstyle().getdataformat() == 167) {          system.out.println("167");         datefmt = "mmmm d yyyy ";     } else if(cell.getcellstyle().getdataformat() == 168) {          system.out.println("168");         datefmt = "m/d/yyyy";     } else if(cell.getcellstyle().getdataformat() == 169) {          system.out.println("169");         datefmt = "d-mmm-yyyy";     } else {         datefmt = cell.getcellstyle().getdataformatstring();     }      system.out.println("datefmt "+datefmt);     value = new celldateformatter(datefmt).format(date);     system.out.println("date "+value); } 

i posting answer in case needs in future.

          if (dateutil.iscelldateformatted(cell)) {                 double val = cell.getnumericcellvalue();                 date date = hssfdateutil.getjavadate(val);                 string datefmt = null;                  if(cell.getcellstyle().getdataformat()==14){                     datefmt = "dd/mm/yyyy";                     value = new celldateformatter(datefmt).format(date);                 }                 else{                     dataformatter fmt = new dataformatter();                     string valueasinexcel = fmt.formatcellvalue(cell);                     value = valueasinexcel;                 }            } 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -