您好,使用 Workbook 读取 Excel 文件时出现以下错误。
Servlet.service() for servlet [dispatcherServlet] in context with path [/project] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.atWarn()Lorg/apache/logging/log4j/LogBuilder;] with root cause
java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.atWarn()Lorg/apache/logging/log4j/LogBuilder;
at org.apache.poi.util.XMLHelper.logThrowable(XMLHelper.java:307) ~[poi-5.2.0.jar:5.2.0]
at org.apache.poi.util.XMLHelper.trySet(XMLHelper.java:275) ~[poi-5.2.0.jar:5.2.0]
at org.apache.poi.util.XMLHelper.getDocumentBuilderFactory(XMLHelper.java:113) ~[poi-5.2.0.jar:5.2.0]
at org.apache.poi.util.XMLHelper.<clinit>(XMLHelper.java:85) ~[poi-5.2.0.jar:5.2.0]
at org.apache.poi.ooxml.util.DocumentHelper.newDocumentBuilder(DocumentHelper.java:47) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.ooxml.util.DocumentHelper.<clinit>(DocumentHelper.java:36) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:393) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:102) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:53) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:282) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:743) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:315) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:59) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:304) ~[poi-ooxml-5.2.0.jar:5.2.0]
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:300) ~[poi-ooxml-5.2.0.jar:5.2.0]
在 Workbook workbook = new XSSFWorkbook(file) 中获取上述异常
FileInputStream file = new FileInputStream(new File(filepath));
Workbook workbook = new XSSFWorkbook(file);
Sheet sheet = workbook.getSheetAt(0);
System.out.println("total number===>"+sheet.getPhysicalNumberOfRows());