java - Iteration error in Excel sheet -


when tried select items item list using excel sheet through java environment, first item selected , executed. next set of iteration not happening.

int i=1;  while (i<=sheet.getlastrownum()  )   {      row = sheet.getrow(i);      string w = row.getcell(0).getstringcellvalue();     //  processing : logic on "items" excel       i++; } 

ok try sample firstly before code. check every column , row visited. maybe better way using iterators.

try {      fileinputstream file = new fileinputstream(new file("c:\\test.xls"));      //get workbook instance xls file      hssfworkbook workbook = new hssfworkbook(file);      //get first sheet workbook     hssfsheet sheet = workbook.getsheetat(0);      //iterate through each rows first sheet     iterator<row> rowiterator = sheet.iterator();     while(rowiterator.hasnext()) {         row row = rowiterator.next();          //for each row, iterate through each columns         iterator<cell> celliterator = row.celliterator();         while(celliterator.hasnext()) {              cell cell = celliterator.next();              switch(cell.getcelltype()) {                 case cell.cell_type_boolean:                     system.out.print(cell.getbooleancellvalue() + "\t\t");                     break;                 case cell.cell_type_numeric:                     system.out.print(cell.getnumericcellvalue() + "\t\t");                     break;                 case cell.cell_type_string:                     system.out.print(cell.getstringcellvalue() + "\t\t");                     break;             }         }         system.out.println("");     }     file.close();     fileoutputstream out =          new fileoutputstream(new file("c:\\test.xls"));     workbook.write(out);     out.close();  } catch (filenotfoundexception e) {     e.printstacktrace(); } catch (ioexception e) {     e.printstacktrace(); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -