包括以下库:
..\lib\ooxml-schemas-1.4.jar;..\lib\poi-ooxml-5.0.0.jar;..\lib\poi-5.0.0.jar;..\lib\ooxml-lib\xmlbeans-4.0.0.jar;..\lib\lib\commons-collections4-4.4.jar;..\lib\commons-compress-1.20.jar
我正在尝试创建和excel文件,并写入它。编译正常。然而,当我运行时,得到一个“没有这样的方法错误”。我注意到CTFont.class存在于ooxml-schemas-1.4.jar中。我想知道在哪个版本中可以找到CTFont.addNewFamily()。
Exception in thread "main" java.lang.NoSuchMethodError: 'org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont.addNewFamily()'
at org.apache.poi.xssf.usermodel.XSSFFont.setFamily(XSSFFont.java:635)
at org.apache.poi.xssf.usermodel.XSSFFont.setFamily(XSSFFont.java:647)
at org.apache.poi.xssf.model.StylesTable.createDefaultFont(StylesTable.java:765)
at org.apache.poi.xssf.model.StylesTable.initialize(StylesTable.java:716)
at org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:130)
at org.apache.poi.ooxml.POIXMLFactory.newDocumentPart(POIXMLFactory.java:94)
at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:591)
at org.apache.poi.ooxml.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:500)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:465)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:255)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:249)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:237)
at WriteDataToExcel.main(WriteDataToExcel.java)发布于 2021-05-31 00:47:03
在类路径中包含poi-ooxml-full-5.0.0.jar和poi-ooxml-lite-5.0.0.jar,并删除ooxml-schemas-1.4.jar。
我从下面的链接得到了答案:java.lang.NoSuchMethodError: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont.addNewFamily()
根据上面的链接,
apache poi版本5.0.0不能再使用ooxml-schemas-1.4.jar。它需要poi-ooxml-lite...jar或poi-ooxml-full...jar。因此,请确保在使用apache poi 5.0.0时,类路径中没有ooxml-schemas-1.4.jar。
https://stackoverflow.com/questions/67760076
复制相似问题