我无法使用selenium web驱动程序中的Apache POI将数据写入第二张excel表。它显示出一个Null点异常错误。但是,我能够在第一张表中写入数据。以下是我的代码,
package RWExcel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class WriteExcel {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File src = new File("D:/selenium/Test/ReadExcel.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wbook = new XSSFWorkbook(fis);
XSSFSheet sheet0 = wbook.getSheetAt(1);
sheet0.getRow(0).createCell(2).setCellValue("Pass");
sheet0.getRow(1).createCell(2).setCellValue("Fail");
FileOutputStream output = new FileOutputStream(src);
wbook.write(output);
wbook.close();
}
}