Java把word转HTML格式
方式一:
maven引入依赖,pom.xml
e-iceblue spire.office.free 5.3.1
然后代码读取DOC内容,保存成HTML,然后再读取HTML。
(input.doc这个要输入完整路径,例如D:/input.doc)
java:
Document doc = new Document();doc.loadFromFile(\"input.doc\", FileFormat.Doc);doc.saveToFile(\"output.html\", FileFormat.Html);String htmlContent = Files.readString(Paths.get(\"output.html\"));
------------------
方式二:
另外一种方式,先转换成DOCX,然后再提取HTML
pom.xml
org.apache.poi poi-ooxml 5.2.2
java:
XWPFDocument docx = new XWPFDocument(new FileInputStream(\"input.doc\"));ByteArrayOutputStream htmlStream = new ByteArrayOutputStream();Document.save(htmlStream, SaveFormat.HTML);String html = htmlStream.toString();