0

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();
         }
Kavan
  • 569
  • 4
  • 21
bala raju
  • 41
  • 1
  • 3
  • try using getWorkbook instead of createWorkbook. read http://www.andykhan.com/jexcelapi/tutorial.html – Kavan Jun 10 '15 at 08:14

1 Answers1

0

Instead of

   WritableWorkbook book = Workbook.createWorkbook(f);

try:

 WritableWorkbook book = Workbook.getWorkbook(File file) ;
Neha S
  • 283
  • 1
  • 3
  • 17
  • WritableWorkbook book = Workbook.getWorkbook(File file) ; what should i write in place of "File file" – bala raju Jun 11 '15 at 06:55
  • Add the below before **WritableWorkbook** statement: `File file = new File("D:\\seleniumreport.xls");` – Neha S Jun 12 '15 at 08:54