上代码
@SneakyThrows
public static void spiceDoc(){
document document = new document();
Section sec = document.addSection();
String htmlText = readTextFromFile("D:\IdeaProjects\export-excel-spring\pdfTradeYiMiaoTwo.html");
sec.addParagraph().appendHTML(htmlText);
File tmpFile = TmpFileUtil.create(".docx");
System.out.println(tmpFile.getPath());
OutputStream outputStream = new FileOutputStream(tmpFile);
document.saveToStream(outputStream, FileFormat.Docx);
outputStream.close();
XWPFdocument doc = new XWPFdocument(new FileInputStream(tmpFile.getPath()));
doc.removeBodyElement(0);
File tmpFileNew = TmpFileUtil.create(".docx");
FileOutputStream fos = new FileOutputStream(tmpFileNew.getPath());
doc.write(fos);
fos.close();
}
jar包:spire.doc-3.6.7.jar-Java文档类资源-CSDN下载



