Home > Web Front-end > JS Tutorial > body text

Comparison of java and javascript to obtain the bookmark position of a word document_javascript skills

WBOY
Release: 2016-05-16 16:43:49
Original
1576 people have browsed it

1.javascript:把IE浏览器的activex都打开,使用如下网页,可以看到书签顺序和位置:

<html>
<head>
<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("</br>");
}
</script>
</head>
<body>
</body>
</html>

Copy after login

java:用poi打开,这里用的是.doc文件,所以用旧一套poi的API,如果是docx,原理是一样的。

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<j;i++){
  Bookmark bookmark = bookmarks.getBookmark(i);
  System.out.println(bookmark.getName());
  System.out.println(i);
  System.out.println(bookmark.getStart());
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template