Retrieve INTEGER values from excel using JAVA -


my aim read excel file uisng poi , print values present in it. if value 5 output must 5. returning 5.0. below code have tried.

    fileinputstream fileinputstream = null;     xssfsheet xssfresultsheet = null;     string filepath = "c:\\myxcel.xlsx";     fileinputstream = new fileinputstream(new file(filepath));     xssfworkbook workbook = null;     workbook = new xssfworkbook(fileinputstream);     xssfresultsheet = workbook.getsheet("sheet1");     int irowcount = xssfresultsheet.getlastrownum();      (int = 1; <= irowcount; i++) {         row resultrow = xssfresultsheet.getrow(i);         system.out.println(resultrow.getcell(0));     } 

my excel has values 1,2,3 output 1.0,2.0,3.0. instead output should 1,2,3

change:

system.out.println(resultrow.getcell(0)); 

to:

system.out.println(new dataformatter().formatcellvalue(resultrow.getcell(0))); 

explanation:

apache-poi provides dataformatter class utility leverage format of content as appears on excel. can choose custom formats too, simple example (cell reference xssfcell object):

excel sheet looks like:

enter image description here

code:

system.out.println(new dataformatter().formatcellvalue(cell)); 

the above line print:

50% $ 1,200 12/21/14 9886605446 

whereas normal print interpret differently:

0.5 1200.0 21-dec-2014 9.886605446e9 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -