java - Apache POI update cell after finishing Webdriver test -
so little complicated explain, i'll try best.
i want have excel file cell call count, purpose of number gets set manually when read data in worksheet reads data row, , @ end of test want add 1 onto number.
public string[] readnewhiredata() { string ex2[] = new string[100]; try { simpledateformat sdf = new simpledateformat("dd/mm/yyyy"); file file = new file("c:/users/saahme/documents/filepath.xls"); workbook workbook = workbookfactory.create(file); sheet worksheet = workbook.getsheetat(1); row rowcount = worksheet.getrow(1); cell count = rowcount.getcell(11); thecount = new bigdecimal(count.getnumericcellvalue()).toplainstring(); row row1 = worksheet.getrow(integer.parseint(thecount)); cell firstname = row1.getcell(0); ex2[0] = firstname.getstringcellvalue(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (invalidformatexception e) { e.printstacktrace(); } return ex2; }
ok when test runs want read thecount , number 1, , means when test getting stringvalue of each row going 1 (i've shortened code down make more readable). , once test finishes want add 1 onto count. tried this.
public void writetoexcel() { try { hssfworkbook workbook2 = new hssfworkbook(); fileoutputstream fos = new fileoutputstream("c:/users/saahme/documents/filepath.xls"); hssfsheet worksheet2 = workbook2.getsheetat(1); hssfrow rowcount = worksheet2.getrow(1); hssfcell celll2 = rowcount.createcell(12); celll2.setcellvalue(thecount + 1); workbook2.write(fos); } catch(filenotfoundexception e) { e.printstacktrace(); } catch(ioexception e) { e.printstacktrace(); } }
but i've realised i'm creating new file , overwriting old 1 isnt want want do, want edit cell @ end of readnewhiredata , add 1 onto life of me whatever i'm trying not work. did try
row rowcount2 = worksheet.getrow(1); cell count2 = rowcount2.getcell(11); count2.setcellvalue(thecount + 1);
but didnt seem work, feel i'm close answer here need hand in nudging me there. in advance assistance :)
Comments
Post a Comment