zoukankan      html  css  js  c++  java
  • 将多个 docx 文件使用 POI 进行合并,生成单个文档,包含图片

    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)
  • 相关阅读:
    python反射
    numpy笔记
    leetcode43
    leetcode-42
    The Github Flow
    leetcode-37
    leetcode-41
    leetcode-40
    TCP扫盲2
    字节码分析与操作
  • 原文地址:https://www.cnblogs.com/zhaopengcheng/p/9821467.html
Copyright © 2011-2022 走看看