//复制当前word所有内容到剪贴板
public void copyWordContent(){
Dispatch textRange = Dispatch.get(doc, "Content").toDispatch(); // 取得当前文档的内容
Dispatch.call(textRange, "Copy");
}
/**
* 把插入点移动到文件最底部
*
*/
public void moveEnd() {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
Dispatch.call(selection, "EndKey", new Variant(6));
}
/**
* 在当前文档末尾拷贝来自另一个文档中的所有内容 *
* @param anotherDocPath
* 另一个文档的磁盘路径
*/
public void copyContentFromAnotherDoc(String anotherDocPath) {
Dispatch wordContent = Dispatch.get(doc, "Content").toDispatch(); // 取得当前文档的内容
Dispatch.call(wordContent, "InsertAfter", "$selection$");// 插入特殊符定位插入点
copyContentFromAnotherDoc(anotherDocPath, "$selection$");
}
/**
* 在当前文档拷贝来自另一个文档中的所有内容 *
* @param anotherDocPath
* 另一个文档的磁盘路径
* @param pos
* 当前文档指定的位置
*/
public void copyContentFromAnotherDoc(String anotherDocPath, String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch range = Dispatch.get(doc2, "Content").toDispatch(); // 取得当前文档的内容
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}