jacob更新目录方法
/**启动word进程*/
ActiveXComponent app = new ActiveXComponent("Word.Application");
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
/**打开word文档*/
Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, new Object[] { docfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
Dispatch activeDocument = app.getProperty("ActiveDocument").toDispatch();
/**获取目录*/
Dispatch tablesOfContents = Dispatch.get(activeDocument,"TablesOfContents").toDispatch();
/**获取第一个目录。若有多个目录,则传递对应的参数*/
Variant tablesOfContent = Dispatch.call(tablesOfContents, "Item", new Variant(1));
/**更新目录,有两个方法:Update 更新域,UpdatePageNumbers 只更新页码*/
Dispatch toc = tablesOfContent.toDispatch();
toc.call(toc, "UpdatePageNumbers");
/**另存为*/
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {
toFile, new Variant(type) }, new int[1]);
/**关闭word文档*/
Dispatch.call(doc, "Close", new Variant(false));
/**退出word进程*/
app.invoke("Quit", new Variant[] {});