简体   繁体   English

硒webdriver不使用Apache POI将数据写入Excel工作表

[英]selenium webdriver not writing data into excel sheet using apache poi

I am trying to read and write data from excel using java selenium webdriver apache poi. 我正在尝试使用java selenium webdriver apache poi从excel读取和写入数据。 But my code is reading data from excel sheet but not write data into excel sheet. 但是我的代码是从excel表读取数据,而不是将数据写入excel表。 I have included all jar files from poi-4.0.1 here is my code 我已经包含了poi-4.0.1中的所有jar文件,这是我的代码

try {

          // Specify the file path which you want to create or write

          File src=new File("E:\\Dharshan\\test.xlsx");

          // Load the file

          FileInputStream fis=new FileInputStream(src);

           // load the workbook

           XSSFWorkbook wb=new XSSFWorkbook(fis);

          // get the sheet which you want to modify or create

           XSSFSheet sh1= wb.getSheetAt(0);

         // getRow specify which row we want to read and getCell which column

         System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());

         System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());

         System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());

         System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());

         System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());

         System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());

        // here createCell will create column

        // and setCellvalue will set the value

         sh1.getRow(0).createCell(3).setCellValue("2.41.0");

         sh1.getRow(1).createCell(3).setCellValue("2.5");

         sh1.getRow(2).createCell(3).setCellValue("2.39");


        // here we need to specify where you want to save file

        FileOutputStream fout = new FileOutputStream(src);

         wb.write(fout);
         fout.close();

          } catch (Exception e) {

           System.out.println(e.getMessage());

          }
}

} }

一旦我用数据更新了Excel工作表后,我便试图从空的Excel工作表中读取数据,现在它正在写入Excel工作表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM