相思资源网 Design By www.200059.com

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>

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());
}
标签:
java,javascript,书签

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“java和javascript获取word文档的书签位置对比”

暂无java和javascript获取word文档的书签位置对比的评论...