本文章纯属博主原创,不允许盗窃抄袭,此具有版权效应
java中将word转换为html导入到ueditor编辑器中(解决图片问题,样式,非常完美)
这几天一直在做将word导入到ueditor中,网上查询了好多资料但是还是有部分缺陷,我这边查阅了很多篇文章综合自己的代码最终写入史册,废话不多说,直接上代码
1.新建工程,导入对应的依赖包
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.10-FINAL</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.10-FINAL</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
工具类代码
public class Word2Html {
/**
* 将Word2007+转成Html
*
* @throws Exception
*/
@Test
public void word2007ToHtml() throws Exception {
String filePath = "E:/学习、练习数据文件夹/test/";
String fileName = "SpringIOC解析.docx";
String htmlName = "SpringIOC解析.html";
final String file = filePath + fileName;
File f = new File(file);
if (!f.exists()) {
System.out.println("Sorry File does not Exists!");
} else {
/* 判断是否为docx文件 */
if (f.getName().endsWith(".docx") || f.getName().endsWith(".DOCX")) {
// 1)加载word文档生成XWPFDocument对象
FileInputStream in = new FileInputStream(f);
XWPFDocument document = new XWPFDocument(in);
// 2)解析XHTML配置(这里设置IURIRe