小编Dha*_*min的帖子

如何使用Java将.docx的段落复制到另一个.docx并保留样式

我试图将内容从.docx中的特定段落复制到另一个空的.docx.我遇到的问题是来自source.docx的样式,项目符号,编号等未保留在目标.docx中.这是我的代码

任何人都可以告诉我上面的代码中添加了哪些更改?提前致谢!!

public class WordFinal {

        public static void main(String[] args) throws IOException, XmlException {

        XWPFDocument doc = new XWPFDocument(new FileInputStream("source.docx"));

        XWPFDocument destDoc =new XWPFDocument(); 

        OutputStream out = new FileOutputStream("Destination.docx"); 

        XWPFParagraph pr =doc.getParagraphs()[1];

        String copy=pr.getText();

        XWPFParagraph paragraphOne = destDoc.createParagraph(); 

        XWPFRun paragraphOneRunOne = paragraphOne.createRun();

        paragraphOneRunOne.setText(copy);

        destDoc.write(out);

         }
             }
Run Code Online (Sandbox Code Playgroud)

java ms-word apache-poi docx4j

5
推荐指数
1
解决办法
7014
查看次数

标签 统计

apache-poi ×1

docx4j ×1

java ×1

ms-word ×1