ActiveXComponent word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(false));
/***************************************************************************
* 删除书签
*
* @param mark 书签名
* @param info 可替换
* @return
*/
public boolean deleteBookMark(String markKey, String info) throws Exception{
Dispatch activeDocument = word.getProperty("ActiveDocument")
.toDispatch();
Dispatch bookMarks = word.call(activeDocument, "Bookmarks")
.toDispatch();
boolean isExists = word.call(bookMarks, "Exists", markKey)
.toBoolean();
if (isExists) {
Dispatch n = Dispatch.call(bookMarks, "Item", markKey).toDispatch();
Dispatch.call(n, "Delete");
return true;
}
return false;
}
/***************************************************************************
* 根据书签插入数据
*
* @param bookMarkKey 书签名
* @param info 插入的数据
* @return
*/
public boolean intoValueBookMark(String bookMarkKey, String info) throws Exception{
Dispatch activeDocument = word.getProperty("ActiveDocument")
.toDispatch();
Dispatch bookMarks = word.call(activeDocument, "Bookmarks")
.toDispatch();
boolean bookMarkExist = word.call(bookMarks, "Exists", bookMarkKey)
.toBoolean();
if (bookMarkExist) {
Dispatch rangeItem = Dispatch.call(bookMarks, "Item", bookMarkKey)
.toDispatch();
Dispatch range = Dispatch.call(rangeItem, "Range").toDispatch();
Dispatch.put(range, "Text", new Variant(info));
return true;
}
return false;
}
posted on 2009-12-08 17:30
Worker 阅读(2469)
评论(3) 编辑 收藏 所属分类:
J2SE/J2EE