日期:2014-05-20  浏览次数:20796 次

请教高手,关于jacob操作word文档的问题,怎么把二份word合并成一个。
本帖最后由 liuzhengkang 于 2010-07-23 18:28:14 编辑 请教高手,关于jacob操作word文档的问题,怎么把二份word合并成一个。

刚在网上找到这么一段代码,
jacob操作API
http://www.cnblogs.com/BruceLeey/archive/2009/09/28/1575577.html
但是没有复制、粘贴的方法,

我现在是想,打开二份word,把其中一个【2.doc】全选复制,然后粘贴到另一个【1.doc】文档的后面,再把【1.doc】另存为【3.doc】,这个【3.doc】就是我要的文档了。
请问下面这几个方法怎么用,我怎么试都不行。

Dispatch.call(range, "Copy");
Dispatch.call(textRange, "Paste");

------最佳解决方案--------------------
用POI,直接取出内容,再合并
------其他解决方案--------------------
不用POI。jacob怎么操作啊。
------其他解决方案--------------------
帖子又沉了,顶上去,希望高手帮忙。。
------其他解决方案--------------------
期待高手。。。
------其他解决方案--------------------
package com.sinosoft.dao;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class Word2Pdf {

static final int wdDoNotSaveChanges = 0;// 不保存待定的更改。
static final int wdFormatPDF = 17;// PDF 格式

public static void main(String[] args) {
List list  = new ArrayList();
File file1= new File("D:\\file1.doc");
File file2= new File("D:\\file2.doc");
File file3= new File("D:\\file3.doc");
list.add(file1);
list.add(file2);
list.add(file3);
uniteDoc(list,"d:\\file.doc");
}
public static void uniteDoc(List fileList, String savepaths) {
    if (fileList.size() == 0 
------其他解决方案--------------------
 fileList == null) {
        return;
    }
    //打开word
    ActiveXComponent app = new ActiveXComponent("Word.Application");//启动word

    try {
        // 设置word不可见
        app.setProperty("Visible", new Variant(false));
        //获得documents对象
        Object docs = app.getProperty("Documents").toDispatch();
        //打开第一个文件
        Object doc = Dispatch
                .invoke(
                        (Dispatch) docs,
                        "Open",
                        Dispatch.Method,
                        new Object[] { (String) fileList.get(0),
                                new Variant(false), new Variant(true) },