使用以下代码从Excel工作表中检索数据:
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class poi_excel {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileInputStream fis =new FileInputStream("F:\\Selenium Using Web Driver\\Plugins\\HEC_login.xlsx");
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sheet=wb.getSheet("script");
XSSFRow row=sheet.getRow(1);
XSSFCell cell=row.getCell(1);
String value = cell.getStringCellValue();
System.out.println(value);
} }
发生以下错误
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/F:/Selenium%20Using%20Web%20Driver/Plugins/poi-bin-3.17-20170915/poi-3.17/poi-ooxml-3.17.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.NullPointerException
at poi_excel.main(poi_excel.java:16)
请提供解决方案以解决此问题。
答案 0 :(得分:0)
XSSFSheet sheet=wb.getSheet("script.type");
输入文件类型(.xlsx或其他)代替type
,然后重试。
编辑:同时检查文件是否在工作目录中。