如何使用 Apache POI 解析和打印项目符号列表?

问题描述 投票:0回答:0

我正在尝试提取 Java 项目中的整个 word 文档,逐段进行并将 XWPFParagraphs 打印回另一个 word 文件。 除了输入文档中的项目符号列表在输出文档中打印为编号列表外,我能够完成我的任务。

这是我复制段落的代码:

static void copyParagraph(XWPFParagraph source, XWPFParagraph target, XWPFNumbering numbering)
    {
        target.getCTP().setPPr(source.getCTP().getPPr());

        source.getRuns().forEach(run -> {
            XWPFRun newR = target.createRun();
            newR.setText(run.getText(0));
            newR.getCTR().setRPr(run.getCTR().getRPr());

            if (!run.getEmbeddedPictures().isEmpty()) {
                XWPFPicture picture = run.getEmbeddedPictures().get(0);
                try {
                    FileOutputStream out = new FileOutputStream(Constants.H1_SECTIONS_IMAGE_DIR + picture.getPictureData().getFileName());
                    out.write(picture.getPictureData().getData());
                    out.close();
                    newR.addPicture(new FileInputStream(Constants.H1_SECTIONS_IMAGE_DIR + picture.getPictureData().getFileName()), picture.getPictureData().getPictureType(), picture.getPictureData().getFileName(), Units.toEMU((int) picture.getWidth()), Units.toEMU((int) picture.getDepth()));
                } catch (IOException | InvalidFormatException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }

我找不到可以在输出文档中保持相同列表类型(项目符号、编号等)的解决方案

java ms-word xml-parsing apache-poi xwpf
© www.soinside.com 2019 - 2024. All rights reserved.