我想用java 打开word编辑器,用jacob实现了,但是不知道怎么检测打开的word什么时候关闭,比如说SQL里面有个word文档,我将它读出来用word打开了,没出现问题,但是当我把已打开的文档编辑好后,点word的红色关闭按钮关闭了,我想在这个时候再将编辑好的文档上传到sql里面,请问我该检测那个关闭事件。,

解决方案 »

  1.   

    呵呵,自己搞定了
    public class invokecom
    {
        public static void main(String[] args) {ActiveXComponent app = new ActiveXComponent("Word.Application"); 
    String inFile = "I:\\edocument\\test.doc"; boolean flag = false;
    try {
    app.setProperty("Visible", new Variant(true)); 
    Dispatch docs = app.getProperty("Documents").toDispatch();
    Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method,
    new Object[] {inFile, new Variant(false), new Variant(false)},
    new int[1]).toDispatch(); 
    Dispatch content = Dispatch.get(doc, "Content").toDispatch(); 
    System.out.print(content.toString());
    while(true){
    if( app.connectToActiveInstance(app.getProgramId()) == null){
       System.out.print("文档编辑已完成,准备上传中...");
       System.exit(0);
    }
    }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }
    }