ApachePOI——如何将表从一个docx复制到另一个docx - 一点教程

您好,我正在尝试将一个表从一个docx文件复制到另一个docx文件,但实际情况是,该表的值在新文档中的表下方和表外部被复制(请参见下面的图片)

Talbe在新的docx里

正如您所见,表的值被复制到表的外部。我使用的是Libre Office,ApachePOI版本3.17,我的电脑运行的是Ubuntu 16.04

我用来执行复制的代码如下

public static void copyTable(XWPFDocument input_doc,XWPFDocument output_doc,
                             int table_index_input, int table_index_output) {

    XWPFTable template_table = input_doc.getTables().get(table_index_input);

    CTTbl ctTbl = CTTbl.Factory.newInstance(); // Create a new CTTbl for the new table
    ctTbl.set(template_table.getCTTbl()); // Copy the template table's CTTbl
    XWPFTable new_table = new XWPFTable(ctTbl, output_doc); // Create a new table using the CTTbl upon

    output_doc.createParagraph();
    output_doc.createTable();// Create a empty table in the document
    output_doc.setTable(table_index_output, new_table);  // Replace the empty table to table2

}

原网址: 访问
创建于: 2023-05-08 09:55:43
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论