Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

again: Getting an existing instance of Excel

2008-05-25
2013-04-17
  • Hi,

    I have this "get existing instance of excel" problem, i find the post: http://sourceforge.net/forum/forum.php?thread_id=1241892&forum_id=40421, but doesn't have answer since 2006, is this feature availabe in the 2.2.4 version? is there an example?

    thanks.

    Alejandro.

     
    • I changed this function in callCom.cpp to do this. Not sure if its worth it. the lack of array support in jcom is a real major limitation.

      HRESULT createInstance(const char* progid, IDispatch** ppIDispatch)
      {
          USES_CONVERSION;
          HRESULT hr = CoInitialize(NULL);
          if(FAILED(hr)) return hr;

          CLSID clsid;
      //    hr = CLSIDFromProgID(T2OLE((LPCSTR)progid), &clsid);
          hr = CLSIDFromProgID(A2COLE(progid), &clsid);
          if(FAILED(hr)) return hr;

          *ppIDispatch = NULL;    // ”O‚Ì‚½‚ß
      /* orig
          hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER,
                              IID_IDispatch, (void**)ppIDispatch);
      */
          // My version that only opens if its not already open
          // Get an interface to the running instance, if any..
          IUnknown *pUnk;
          hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);

          if(hr==S_OK)
          {
              // Get IDispatch interface for Automation...
              hr = pUnk->QueryInterface(IID_IDispatch, (void **)ppIDispatch);
          }
          // Release the no-longer-needed IUnknown...
          pUnk->Release();

          if(hr != S_OK)
              hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER,
              IID_IDispatch, (void**)ppIDispatch);

          return hr;
      }

       
  • TADev
    TADev
    2010-06-09

    We've been using the 2.2.4 jar - I'm going to try your change to the cpp source, and build. Thanks.