尝试在eclipse中使用selenium JUni4 Web驱动程序打开excel文件时出现以下错误。错误和代码如下所示。我是JAVA的新手。请帮忙。
public void xlRead_TC(String sPath, int sSheet) throws Exception{
//Workbook book = Workbook.createWorkbook(f);
System.out.println("Step 1B - Opening excel files Reached");
File myxl = new File(sPath);
FileInputStream myStream = new FileInputStream(myxl);
//Workbook w;
//w = Workbook.getWorkbook(myStream);
XSSFWorkbook myWB = new XSSFWorkbook(myStream);
//XSSFSheet mySheet = myWB.getSheetAt(sSheet); // Referring to 1st sheet
//xRows_Inp = mySheet.getLastRowNum()+1;
//xCols_Inp = mySheet.getRow(0).getLastCellNum();
System.out.println("Rows are " + xRows_Inp);
System.out.println("Cols are " + xCols_Inp);
//Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };
//xRows_TC = mySheet.getLastRowNum()+1;
//xCols_TC = mySheet.getRow(0).getLastCellNum();
//System.out.println("Rows are " + xRows_TC);
//System.out.println("Cols are " + xCols_TC);
//xData_TC = new String[xRows_TC][xCols_TC];
}
异常
java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:154)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
答案 0 :(得分:1)
您似乎运行旧版本的POI,但仍需要dom4j第三方库。您有两种选择:
1)升级到最新版本的POI,不再需要此库
2)将dom4j jar文件添加到类路径中。 jar文件是POI二进制分发的一部分。
答案 1 :(得分:0)
我有时会像你一样受到质疑。您可以这样做:在IDE中重建项目+刷新项目。 如果仍然无效,则应重新启动IDE。希望这有帮助:))