如何使用java for selenium webdriver在一个excel表中编写2个不同的结果

时间:2013-10-11 10:58:22

标签: java excel selenium

场景是首先我执行一个结果并创建excel并在其中更新。现在我再次执行第二个结果并尝试在同一张不同的行中更新,但我得到两个结果在一张表中。它只显示第二个结果。

     FileOutputStream exlFileName= new FileOutputStream("D:\\Screenshot\\testExcel.xls");
     WritableWorkbook exlWorkBook = Workbook.createWorkbook(exlFileName);
     WritableSheet exlWorkSheet1 = exlWorkBook.createSheet("Preload data check",0);
     Label Sheet1cellContent = new Label(0,0,"LAST NAME",cellFormat);
     Label Sheet1cellContent1 = new Label(1,0,"FIRST NAME",cellFormat);
     Label Sheet1cellContent2 = new Label(2,0,"DOB",cellFormat);
     Label Sheet1cellContent3 = new Label(3,0,"GENDER",cellFormat);
     Label Sheet1cellContent4 = new Label(4,0,"ADMIT DATE AND TIME",cellFormat);
     Label Sheet1cellContent5 = new Label(5,0,"PROVIDER NAME",cellFormat);
     Label Sheet1cellContent6 = new Label(6,0,"BILL TYPE",cellFormat);
     Label Sheet1cellContent7 = new Label(7,0,"DOS DATE AND TIME",cellFormat);
     Label Sheet1cellContent8 = new Label(8,0,"SCREENSHOT",cellFormat);

     exlWorkSheet1.addCell(Sheet1cellContent);
     exlWorkSheet1.addCell(Sheet1cellContent1);
     exlWorkSheet1.addCell(Sheet1cellContent2);
     exlWorkSheet1.addCell(Sheet1cellContent3);
     exlWorkSheet1.addCell(Sheet1cellContent4);
     exlWorkSheet1.addCell(Sheet1cellContent5);
     exlWorkSheet1.addCell(Sheet1cellContent6);
     exlWorkSheet1.addCell(Sheet1cellContent7);
     exlWorkSheet1.addCell(Sheet1cellContent8);

这是我现在为第二个结果编写代码的第一个结果。

 FileOutputStream exlFileName= new FileOutputStream("D:\\Screenshot\\testExcel.xls");   
 WritableWorkbook exlWorkBook = Workbook.createWorkbook(exlFileName); 
 WritableSheet exlWorkSheet1 = exlWorkBook.createSheet("Preload data check",0); 
 Label Sheet1cellContent10 = new Label(1,5,"CPT Description",cellFormat);
 Label Sheet1cellContent12 = new Label(2,5,"Modifier1",cellFormat);
 Label Sheet1cellContent13 = new Label(3,5,"Modifier2",cellFormat); 
 Label Sheet1cellContent14 = new Label(4,5,"ICD1",cellFormat);
 Label Sheet1cellContent15 = new Label(5,5,"ICD2",cellFormat); 
 Label Sheet1cellContent16 = new Label(6,5,"Dx Notes",cellFormat); 
 Label Sheet1cellContent17 = new Label(7,5,"DOS date",cellFormat); 
 Label Sheet1cellContent18 = new Label(8,5,"Provider name",cellFormat); 
 Label Sheet1cellContent19 = new Label(9,5,"Screenshot",cellFormat);            
 exlWorkSheet1.addCell(Sheet1cellContent9);
 exlWorkSheet1.addCell(Sheet1cellContent10);
 exlWorkSheet1.addCell(Sheet1cellContent12); 
 exlWorkSheet1.addCell(Sheet1cellContent13);
 exlWorkSheet1.addCell(Sheet1cellContent14); 
 exlWorkSheet1.addCell(Sheet1cellContent15);
 exlWorkSheet1.addCell(Sheet1cellContent16); 
 exlWorkSheet1.addCell(Sheet1cellContent17); 
 exlWorkSheet1.addCell(Sheet1cellContent18); 
 exlWorkSheet1.addCell(Sheet1cellContent19);

请帮助我解决这个问题。

1 个答案:

答案 0 :(得分:0)

尝试查看工作簿或工作表是否已存在,而不是始终创建工作簿和工作表。如果存在则在编辑模式下打开它并添加新的结果集。