CodePudding user response:
A month without bosses manage meCodePudding user response:
Combined with Jacob can update directoryPackage com. Key. Words. Convert;
The import com. Jacob. ActiveX. ActiveXComponent;
The import com.jacob.com.Dispatch;
The import com.jacob.com.Variant;
Public class WordCatalog {
/* *
* directory to generate
* @ param oldPath source file
* @ param wirtePath store path
* @ return
*/
Public static void updateWord (String oldPath, String wirtePath) {
ActiveXComponent app=new ActiveXComponent (" Word. Application ");//start word
Try {
//app. SetProperty (" Visible ", new Variant (true));//set the word invisible
App. SetProperty (" Visible ", new Variant (false));
Dispatch docs=app. GetProperty (" Documents "). ToDispatch ();
Dispatch doc=Dispatch. Invoke (docs, "Open", Dispatch Method,
The new Object [] {oldPath, new Variant (false), the new Variant (true)}, new int [1]). ToDispatch ();
Dispatch activeDocument=app. GetProperty (" activeDocument "). ToDispatch ();
/* *
* part of the code update directory
*
* access catalog */
Dispatch tablesOfContents=Dispatch. Get (activeDocument, "tablesOfContents"). The toDispatch ();
/* * get the first catalogue, if you have multiple directories, then transfer the corresponding parameter */
The Variant tablesOfContent=Dispatch. Call (tablesOfContents, "Item", the new Variant (1));
/* * Update catalog, there are two methods: Update to Update the domain, UpdatePageNumbers Update only page */
Dispatch the toc=tablesOfContent. ToDispatch ();
Toc. Call (toc, "Update");
Complete System. Out. Println (" save as ");
Dispatch. Call (doc, "SaveAs", wirtePath);//save file
Dispatch. Call (doc, "Close", the new Variant (false));
System. The out. Println (" is over ");
} the catch (Exception e) {
e.printStackTrace();
} the finally {
App. Invoke (" Quit ", new Variant [] {});
App. SafeRelease ();
}
}
}
CodePudding user response:
Thanks for this I know but this only supports Windows environment in Linux is not supported by theCodePudding user response: