jacob对word的一些操作

	 //复制当前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;
			}
		}
	}

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值