java - Apache POI find last cell in row -


i have following code reads spreadsheet , writes pipe-delimeted file. rows have differing length. last cell shouldn't appended pipe character (but does). tried things https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/row.html#getlastcellnum() cannot make work.

xssfworkbook wb = new xssfworkbook(pathandfilename);     (int = 0; < wb.getnumberofsheets(); i++) {         xssfsheet sheet = wb.getsheetat(i);         string outfilename = path + "\\" + prefix + sheetname + postfix;         printwriter outfilewriter = new printwriter(outfilename, "utf-8");         iterator<row> rowiterator = sheet.iterator();         while (rowiterator.hasnext()) {             row row = rowiterator.next();             iterator<cell> celliterator = row.celliterator();             while (celliterator.hasnext()) {                 cell cell = celliterator.next();                 cell.setcelltype(cell.cell_type_string);                 outfilewriter.print(cell.getstringcellvalue() + "|");             }             outfilewriter.print("\n");         }         outfilewriter.close();     } wb.close(); 

i fixed such:

while (rowiterator.hasnext()) {     row row = rowiterator.next();     list<string> recordarry = new arraylist<string>();     iterator<cell> celliterator = row.celliterator();     while (celliterator.hasnext()) {         cell cell = celliterator.next();         cell.setcelltype(cell.cell_type_string);         recordarry.add(cell.getstringcellvalue() + "|");     }     stringbuilder recordstring = new stringbuilder();     (string elem : recordarry) {         recordstring.append(elem);     }     string recordstring2 = stringutils.chomp(recordstring.tostring(), "|");     outfilewriter.print(recordstring2);     outfilewriter.print("\n"); } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -