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

普里亚达山

我正在尝试使用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工作表

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法使用for循环(Apache_poi)在Excel工作表中写入数据

如何使用Java中的Apache POI将元数据写入Excel工作簿

使用ActiveX将数据写入excel并更改工作表名称--Matlab

Python /熊猫:使用“循环”将多个数据框写入Excel工作表

使用XLSX Writer将数据透视表写入Excel工作簿范围

无法使用熊猫将完整的数据透视表写入现有excel工作簿中的新工作表

如何在Java中使用Apache POI将数据验证添加到Excel工作表的整个列中?

使用Apache POI删除Excel工作表

使用Apache POI复制Excel工作表

如何使用openpyxl将列表内容写入Excel工作表

使用Pandas将Dataframe行写入Excel工作表

使用应用系列将两个列表中的数据框写入 Excel 文件的两个单独工作表

使用Apache POI从Java中的Excel工作表中读取数据

如何在java中使用Apache POI从Excel工作表中提取数据(查找框架)

使用Apache POI将文件嵌入Excel中的XSSF工作表

如何使用apache-poi将Excel工作表中的值设置为Pojo对象?

使用 Apache POI 将工作表附加到 Excel 文件 - NullPointerException 引起的 POIXMLException

使用 xlsxwriter 将数据从 Dataframe 写入 Excel 表时出错

使用 sql 表中的 powershell 将数据写入 excel

如何使用Apache POI在Excel中逐列写入数据?

如何在Button click事件上将JavaFX Table数据转换为Apache POI Excel工作表?

使用可变工作表名称将表的一部分写入Excel文件

使用python写入特定的Excel工作表

Rails,如何使用“ roo” gem替换或写入excel工作表文件中的数据

使用python pandas在excel中的多个工作表中写入数据

在while循环中使用xlsxwriter将多个公式写入Excel工作表

使用Apache POI更新基于CSV工作表的Excel工作表值

如何使用Excel中的POI从Excel工作表获取单独的列数据以将其存储在对象的数组列表中?

使用 Google Apps 脚本将 kmz 中的数据写入工作表