1 添加 maven 依赖,需要使用 poi 的依赖项
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> </dependency>
- 对于对个文档合并中间需要添加分页符有两种方式:段前添加分页符、段后添加分页符
段后添加分页符示例代码
//段后添加分页符 XWPFDocument doc; XWPFParagraph paragraph = doc.createParagraph(); paragraph.setPageBreak(true);
段前添加分页符示例
//段前添加分页符 XWPFDocument doc; XWPFRun run = doc.getLastParagraph().createRun(); run.addBreak(BreakType.PAGE)