DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> java和javascript獲取word文檔的書簽位置對比
java和javascript獲取word文檔的書簽位置對比
編輯:關於JavaScript     

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());
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved