java - 使用 Apache POI 更新 .docx 文件的页眉

标签 java file file-io apache-poi .doc

如何使用 Apache POI 3.7 API 更新 .docx 文件的页眉?

最佳答案

由于您的文档是.docx 格式,因此您需要使用POI 项目的XWPF 组件API。您可能会发现 org.apache.poi.xwpf.usermodel.XWPFHeader 类很有用 (Javadoc),但我自己从未使用过它。

我找不到使用 XWPF 执行此操作的良好引用,但以下说明描述了使用 HWPF 访问 header ,这是旧 Word 文档(又名 .doc 文档)的类似界面:

To get at the headers and footers of a Word document, first create a org.apache.poi.hwpf.HWPFDocument. Next, you need to create a org.apache.poi.hwpf.usermodel.HeaderStores, passing it your HWPFDocument. Finally, the HeaderStores gives you access to the headers and footers, including first / even / odd page ones if defined in your document. Additionally, HeaderStores provides a method for removing any macros in the text, which is helpful as many headers and footers do end up with macros in them.

page those instructions are from暗示在 HWPF 中头文件支持从来没有那么好,更不用说 XWPF 了。更多坏消息,this other Apache page听起来好像 XWPF 开发几乎停滞不前。您想要执行的操作可能已计划但尚未得到支持。

关于java - 使用 Apache POI 更新 .docx 文件的页眉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430198/

相关文章:

Java - 链接列表泛型子列表

java - Java中的文件删除

c - 在 fopen 中使用 arg vector

file-io - 如何在 Haskell 中创建内存中的句柄?

c++ - 在 C++ 中为文件 I/O 包含其他文件

java - 尝试从 firebase 接收数据时获取空对象引用

java - 在两个文件路径之间建立相对路径

java - SOA 中的事务

java - 将自定义对象数组保存到文件并在java中再次读取?

c - 在C语言的文本文件中查找字符串