最近在做Word转Html时遇到了使用POI的4.2.1版本时报错:
经过对比发现4.2.1版本比旧版本多了ooxml包,导致找不到POIXMLDocumentPart,所以这里的解决方案有两个:
1.可以在项目中把旧版本的jar包源码修改后上传到maven仓库。
2.依旧使用4.2.1版本并把配套的jar包依赖一同升级。
本篇文章介绍第二种解决方法。
三、依赖包依赖包中主要是xdocreport的版本一定要升级到2.0.2。
四、代码实现org.apache.poi poi 4.1.2 org.apache.poi poi-scratchpad 4.1.2 org.apache.poi poi-ooxml 4.1.2 fr.opensagres.xdocreport xdocreport 2.0.2 org.apache.poi ooxml-schemas 1.4
//将word转为html代码
File f = new File(file);
InputStream in = new FileInputStream(f);
XWPFDocument document = new XWPFDocument(in);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XHTMLConverter.getInstance().convert(document, outputStream, null);
String value = new String(outputStream.toByteArray());



