如何在word文件中创建或更新目录? [英] How to create or update table of contents in a word file?

查看:72
本文介绍了如何在word文件中创建或更新目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 Apache POI 或 docx4j 在 Java 中读取或写入 word 文档.但是我在 Word 文件中找不到任何创建或更新目录的参考.Java中是否有其他API可以支持TOC?或者,是否可以在 Apache POI 或 docx4j 中选择创建或更新 TOC?

I can read or write word document in Java using Apache POI or docx4j. But I cant find any references to create or update table of contents in a Word file. Is there any other API can support TOC in Java? Or, is it possible in Apache POI or docx4j to have options to create or update TOC?

推荐答案

要使用 apache poi 创建目录,您可以使用:

To create table of contents with apache poi you can just use:

doc.createTOC();

不过好像有点问题.TOC 已创建,但 (MS Office pro 2010) 似乎无法将其识别为 TOC,并且引用不起作用.

But it seems a bit buggy. The TOC is created but the (MS Office pro 2010) does not seem to recognize it as TOC and the references are not working.

或者您可以致电:

doc.enforceUpdateFields();

这将在 word 文档中创建一个弹出窗口:此文档包含可能引用其他文件的字段.您要更新此文档中的字段吗?",如果您正在打开一个新文档,这看起来有点不可靠:)

This will create a popup in word document with: "This document contains fields that may refer to other files. Do you want to update the fields in this document?", which looks a bit dodgy if you are opening a new doc :)

这篇关于如何在word文件中创建或更新目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆