Caused by: java.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocumentPart at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.getFontsDocument(XWPFStylesDocument.java:1477)
报错内容如上: NoClassDefFoundError: org/apache/poi/POIXMLDocumentPart
根据搜索得到该错误是由于POI组件XWPF最新版本也只支持3.X版本的POI导致。由于某段时间框架调整升级到了4.X,但未对该代码相关功能进行回归测试,所以出现异常。
参考:https://blog.csdn.net/u011852988/article/details/123789135 内容将处理方式整理如下:
1、下载Central Repository: fr/opensagres/xdocreport/org.apache.poi.xwpf.converter.core/1.0.6源码
import org.apache.poi.ooxml.POIXMLDocumentPart;
private static XWPFSettings getSettings( XWPFDocument document )
{
for ( POIXMLDocumentPart p : document.getRelations() )
{
PackageRelationshipCollection relationships = p.getPackagePart().getPackage().getRelationships();
for (PackageRelationship relationship : relationships) {
String relationshipType = relationship.getRelationshipType();
if ( relationshipType.equals( XWPFRelation.SETTINGS.getRelation() ) )
{
return (XWPFSettings) p;
}
}
}
return null;
}
private static List<ThemeDocument> getThemeDocuments( XWPFDocument document )
{
List<ThemeDocument> themeDocuments = new ArrayList<ThemeDocument>();
for ( POIXMLDocumentPart p : document.getRelations() )
{
PackageRelationshipCollection relationships = p.getPackagePart().getPackage().getRelationships();
for (PackageRelationship relationship : relationships) {
String relationshipType = relationship.getRelationshipType();
if ( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme".equals( relationshipType ) )
{
try
{
InputStream inputStream = p.getPackagePart().getInputStream();
ThemeDocument theme = ThemeDocument.Factory.parse( inputStream );
themeDocuments.add( theme );
}
catch ( Throwable e )
{
e.printStackTrace();
}
}
}
}
return themeDocuments;
}
private static List<FontsDocument> getFontsDocument( XWPFDocument document )
{
List<FontsDocument> fontsDocuments = new ArrayList<FontsDocument>();
for ( POIXMLDocumentPart p : document.getRelations() )
{
PackageRelationshipCollection relationships = p.getPackagePart().getPackage().getRelationships();
for (PackageRelationship relationship : relationships) {
String relationshipType = relationship.getRelationshipType();
// "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"
if ( XWPFRelation.FONT_TABLE.getRelation().equals( relationshipType ) )
{
try
{
InputStream inputStream = p.getPackagePart().getInputStream();
FontsDocument fontsDocument = FontsDocument.Factory.parse( inputStream );
fontsDocuments.add( fontsDocument );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
}
return fontsDocuments;
}
原文地址:https://blog.csdn.net/tian168no/article/details/128693916
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_20920.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。