This article mainly introduces the code comparison between java and javascript to obtain the bookmarks of Word documents. For more information, see section 1. javascript: Open activex in IE and use the following webpage to view the order and position of bookmarks:
《script》var word;word = new ActiveXObject("Word.Application");var range = word.Range;word.Visible = true;var path = "D:\\xxx\\xxx\\xx.doc";word.Documents.Open(path);for(var i=1;i<=word.ActiveDocument.Bookmarks.count;i++){ document.write(word.ActiveDocument.Bookmarks(i).Name); document.write(" "); document.write(word.ActiveDocument.Bookmarks(i).Range.BookmarkID); document.write("
");}《script》
Java: open with poi, and use the. DOC file. Therefore, use the old set of poi APIs. If it is docx, the principle is the same.
FileInputStream in = new FileInputStream("D:\\xxx\\xxx\\xx.doc");HWPFDocument doc = new HWPFDocument(in);Bookmarks bookmarks = doc.getBookmarks();for(int i=0,j=bookmarks.getBookmarksCount();i