How to add new excel sheet in existing excel file in runtime using java (jxl) in Webdriver

3,929 views
Skip to first unread message

Umamaheshwar Thota

unread,
Jul 16, 2013, 10:27:36 AM7/16/13
to webd...@googlegroups.com

I have searched but i didn't get any success for finding the answer to my issue. My issue is "How to add new excel sheet in existing excel file in runtime using java(jxl) in Webdriver."

I have tried using below code, used in 2 different classes.

1st sheet:

FileOutputStream  fo = new FileOutputStream("./700Credit_AccProfile_FV_Results_"+cdate+".xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("700Credit_FV_Zip_Results", 0);


2nd sheet:

FileOutputStream fo = new FileOutputStream("./700Credit_AccProfile_FV_Results_"+cdate+".xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("700Credit_FV_City_Results", 1);

1st sheet is created successfully but while creating 2nd sheet, it is overwriting after execution is complete. I am using JXL . Please help me out with this issue. Help will be appreciated.

Krishnan Mahadevan

unread,
Jul 16, 2013, 10:53:50 AM7/16/13
to webdriver
How is this a WebDriver question ?
You should try a JXL specific forum or generic forums such as stackoverflow.

Please help keep this forums relevant by posting queries that are related to Selenium/WebDriver ONLY.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

fmtjatt

unread,
Jul 16, 2013, 6:41:33 PM7/16/13
to webd...@googlegroups.com
Could it be that you are creating workbook twice and it is overwriting the previous one?


FileOutputStream fo = new FileOutputStream("./700Credit_AccProfile_FV_Results_"+cdate+".xls"); WritableWorkbook wwb = Workbook.createWorkbook(fo); WritableSheet ws = wwb.createSheet("700Credit_FV_Zip_Results", 0);


2nd sheet:

FileOutputStream fo = new FileOutputStream("./700Credit_AccProfile_FV_Results_"+cdate+".xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("700Credit_FV_City_Results", 1
);

Try opening the workBook instead of creating it in second sheet.

Umamaheshwar Thota

unread,
Jul 17, 2013, 10:21:04 AM7/17/13
to webd...@googlegroups.com
Hi fmtjatt,

You are correct, i the workbook is creating twice, i have modified the code accordingly and now i am able to print the results in both the excel sheets after creating.

cheers,
Mahesh

sridhar ..

unread,
Jul 19, 2013, 2:21:44 PM7/19/13
to webd...@googlegroups.com
Hi Mahesh,

Interesting topic,could you please share the code with screenshot or Example.Hope it will be useful to all.

Advance thanks...

Regards,
Sri.

Umamaheshwar Thota

unread,
Aug 13, 2013, 3:39:32 AM8/13/13
to webd...@googlegroups.com
Hi Sridhar,

Please find the below code, i have used for printing the test results in different sheets of the same Excel file using Jxl.

//Create the Result xls file
        fo = new FileOutputStream("./Admin_AccProfile_FV_Results_"+cdate+".xls");
        wwb = Workbook.createWorkbook(fo);
        ws = wwb.createSheet("Credit_FV_Zip_Results", 0);
        ws1 = wwb.createSheet("Credit_FV_City_Results", 1);
        ws2 = wwb.createSheet("Credit_FV_Phone_Results", 2);

Cheers,
Mahesh
Reply all
Reply to author
Forward
0 new messages