Unable to write test results in existing excel using JExcelApi

124 views Asked by At

I am unable to write test results in existing excel using selenium I have tried but always new sheet override my existing sheet

      String usernamevalidationmsg = a.findElement(By.id("UserNameRequired")).getText()

      String usernamevalidationexpected = "Email is required.";

      if (usernamevalidationmsg.equals(usernamevalidationexpected))
      {
        try
        { 
                   FileOutputStream f = new FileOutputStream("D:\\seleniumreport.xls",true);
                   WritableWorkbook book = Workbook.createWorkbook(f);
                   WritableSheet sheet = book.getSheet(0);
                   Label l = new Label(1, 2, "Pass");
                   sheet.addCell(l);
                   book.write(); 
                   book.close(); 
         }
         catch (Exception e)
         {
                   e.printStackTrace();
         }
1

There are 1 answers

2
Neha S On

Instead of

   WritableWorkbook book = Workbook.createWorkbook(f);

try:

 WritableWorkbook book = Workbook.getWorkbook(File file) ;