![](/img/trans.png)
[英]How to create a new sheet in an excel file using apache poi in selenium webdriver with java
[英]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.