get number of columns of a particular row in given excel using Java -


i want number of columns of particular row in excel. how possible? used poi api

but columns count 7 .

    try             {                 fileinputstream = new fileinputstream(file);                 workbook = new hssfworkbook(fileinputstream);                 sheet sheet = workbook.getsheet("0");                   int numberofcells = 0;                 iterator rowiterator = sheet.rowiterator();                 /**                  * escape header row *                  */                 if (rowiterator.hasnext())                 {                     row headerrow = (row) rowiterator.next();                     //get number of cells in header row                     numberofcells = headerrow.getphysicalnumberofcells();                 }                 system.out.println("number of cells "+numberofcells);  } 

i want number of columns @ particular row number 10 . excel columns not same

there 2 things can do

use

int noofcolumns = sh.getrow(0).getphysicalnumberofcells(); 

or

int noofcolumns = sh.getrow(0).getlastcellnum(); 

there fine difference between them

  1. option 1 gives no of columns filled contents(if 2nd column of 10 columns not filled 9)
  2. option 2 gives index of last column. hence done 'getlastcellnum()'

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -