簡體   English   中英

硒webdriver不使用Apache POI將數據寫入Excel工作表

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

我正在嘗試使用java selenium webdriver apache poi從excel讀取和寫入數據。 但是我的代碼是從excel表讀取數據,而不是將數據寫入excel表。 我已經包含了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