java - Every time I write to excel, it overwrites the entire file with a blank file - PUZZLED -


what trying ontestfailure (testng) trying write pass/fail specified column. in below code, wanted little test write fail specified cell. what's happening is, instead of writing pass/fail specified cell, literally overwrites entire file , erases of data , puzzled why that's happening. have looked on here , googled cannot find answer. below following code:

 @override public synchronized void ontestfailure(itestresult tr){     try {         workbook workbook = workbook.getworkbook(new file(testdata), workbooksettings);         writableworkbook wb = workbook.createworkbook(new file(testdata), workbook);         writablesheet ws = wb.getsheet("ordereditqa3");         label label = new label(5,2, "fail");         ws.addcell(label);         wb.write();     } catch (ioexception e) {         e.printstacktrace();     } catch (biffexception b){         system.out.print("error!");     } catch (writeexception we){         system.out.print("");     } } 

any appreciated.

updated...

below class use test data returned dataprovider , load of elements specified sheet. below code

// code test data

protected static object[][] loadtestdata(string sheetname)throws biffexception, ioexception{     sheet sheet = null;     try{         sheet = getworkbook().getsheet(sheetname);         rowcount = sheet.getrows();         colcount = sheet.getcolumns();         data = new string[rowcount -1][colcount-1];         int ci;         int cj;         ci=0;         for(int i=1; i< rowcount; i++, ci++){             cj=0;             for(int j=1; j< colcount; j++, cj++){                 cell cell = sheet.getcell(j,i);                 if(cell.getcontents().isempty()){ continue;}                 system.out.print(cell.getcontents() + "\n");                 data[ci][cj] = cell.getcontents();             }         }     }catch (ioexception io){         system.out.print(string.format("file: %s not found!", testdata));     }     getworkbook().close();     return data; } 

//code retrieve element attributes:

@beforeclass protected static list<string> loadelements()throws biffexception, ioexception {     sheet sheet = null;     sheet = getworkbook().getsheet("elements");     rowcount = sheet.getrows();     colcount = sheet.getcolumns();     list<string> list = new arraylist<>(rowcount);     (int = 1; < rowcount; i++) {         (int j = 0; j < colcount; j++) {             cell cell = sheet.getcell(j,i);             if(cell.getcontents().isempty()) {continue;}             string cellcontents = cell.getcontents();             list.add(cellcontents);             system.out.print(cell.getcontents() + "\n");         }     }     elements = list;     getworkbook().close();     return list; } 

just forgot pesky close() method

@override public synchronized void ontestfailure(itestresult tr){     try {         workbook workbook = workbook.getworkbook(new file(testdata), workbooksettings);         writableworkbook wb = workbook.createworkbook(new file(testdata), workbook);         writablesheet ws = wb.getsheet("ordereditqa3");         label label = new label(5,2, "fail");         ws.addcell(label);         wb.write();         wb.close();     } catch (ioexception e) {         e.printstacktrace();     } catch (biffexception b){         system.out.print("error!");     } catch (writeexception we){         system.out.print("");     } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -