如何把table放在每一頁的頁首

你好:
我有一個兩列的Table,想要放在word多頁中的每一頁首處,該如何實現此功能呢?我是使用aspose words Java版本。

@accepter,

请将以下资源压缩成ZIP格式并附上.zip文件用于测试:

  • 包含两列表格的简化源 Word 文档
  • 显示所需输出的预期 Word 文件。 您可以使用 MS Word 手动创建此文件。

一旦您准备好这些信息,我们就会开始调查您的特定场景,并为您提供代码以使用 Aspose.Words 实现相同的输出。

你好:
我想呈現的資源範本檔如附件。productInfo-temp-q.zip (24.5 KB)

@accepter,

如果您想在每一页的开头在第三页上显示第三个表格,那么您可以使用以下 Java 代码将其移动到 Header story:

Document doc = new Document("C:\\Temp\\230927\\productInfo-temp-q.docx");
Section section = doc.getFirstSection();
Table table = section.getBody().getTables().get(2);
HeaderFooter headerFooter =
        section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
headerFooter.insertBefore(table, headerFooter.getLastChild());
doc.save("C:\\Temp\\230927\\awjava-21.6.docx");

希望,这有助于实现您正在寻找的东西。

@awais.hafeez,
謝謝您,這段原始碼非常有用。

1 Like