夸克网盘分享了jar「spire.doc for java」
链接:https://pan.quark.cn/s/9064a2245604
提取码:EGaH
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>11.4.2</version>
</dependency>
<!--jar包自行下载并配置 或者 目录下创建lib直接引入jar包-->
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spirej.doc.cracked</artifactId>
<version>11.4.2</version>
</dependency>
</dependencies>
去头部警告
/**
* 使用spire.Doc 会出现一个水印可以通过这个方法去除水印
* @param docFilePath 生成新路径
*/
private static void restWord(String docFilePath) {
try (FileInputStream in = new FileInputStream(docFilePath)) {
XWPFDocument doc = new XWPFDocument(OPCPackage.open(in));
List<XWPFParagraph> paragraphs = doc.getParagraphs();
if (paragraphs.size() < 1) {
return;
}
XWPFParagraph firstParagraph = paragraphs.get(0);
if (firstParagraph.getText().contains("Spire.Doc")) {
doc.removeBodyElement(doc.getPosOfParagraph(firstParagraph));
}
OutputStream out = new FileOutputStream(docFilePath);
doc.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}