使用 Apache POI 更新 .docx 文件的页眉 [英] Updating a .docx file's page header using Apache POI
问题描述
如何使用 Apache POI 3.7 API 更新 .docx
文件的页眉?
How can I update the page header of a .docx
file using the Apache POI 3.7 API?
推荐答案
首先,调用 getHeaderFooterPolicy() 在你的 XWPFDocument 上,它返回一个 HeaderFooterPolicy.从中,您可以确定页面的适当标题(例如默认、首页等)
First up, call getHeaderFooterPolicy() on your XWPFDocument, which returns a HeaderFooterPolicy. From that, you can identify the appropriate header for your page (eg Default, First Page etc)
一旦你有了合适的 XWPFHeader您想要更改的内容,然后您可以像编辑任何其他文档部分一样对其进行编辑.您可以获取表格、段落等,然后删除它们、添加新的、更改它们的文本等.这与编辑主文档的过程相同.
Once you have the appropriate XWPFHeader that you want to change, then you can go about editing it as any other document part. You can fetch the tables, the paragraphs etc, then remove them, add new ones, change the text of them etc. It's all the same process then as editing the main document.
这篇关于使用 Apache POI 更新 .docx 文件的页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!