Menu

Event monitoring with Word and Excel

Help
Teletobi
2004-12-02
2013-05-20
  • Teletobi

    Teletobi - 2004-12-02

    Hi everyone,

    I'm implementing an interface to Word and Exel with jacob 1.8 on a WinXP machine with Office XP. Everything works fine for me but when it comes to event handling I'm encountering some difficulties.

    With the samples in the jacob18.zip comes an event handling example using Internet Explorer. This one works. But when I try to initialize DispatchEvents for Excel with new DispatchEvents(excelObject, eventClassInstance, "Excel.Application") I always get an error that IProvideClassInfo could not be found. Taking a look inside the dll-code I have found out, that a registry-key is searched whicht is not there (no TypeLib key for Excel!). I also tried to load the Excel.exe (TypeLib for XP) but nothing changed.

    Has anyone some good idea what went wrong or a workaround? I'm trying to implement one to get at least the information wheather the application or document is still open (is there a way to ask if a COM-Object is still alive?) to trigger a ClosedListener.

    Thanks for help,
    teletobi

     
    • Veera

      Veera - 2005-02-28

      Hi Teletobi,

      Where you able to monitor events in Java from Word or Excel.

      I am also trying to get a message or message to check whether Word or Excel is open so that i don't error in my Java. Currently what is happening is We open Word or Excel from within our application where we do printing and then we close the application. If the user closes Word/Excel then when i try to close the application from Java i get "Can't map name to dispid: ActiveDocument" error. Is there anyway to find whether word or excel is already closed?

       
      • Teletobi

        Teletobi - 2005-03-01

        Hi,

        event monitoring works fine for me with word. You can find a brief indroduction how to use it at http://danadler.com/jacob/ , section "Events". The example uses ScriptControl. To find out the right event names you can use the object cataloge (Right name? Don't now how it is named in English, so I just translated it.) in word's visual basic editor and pick up all the entries marked with a flash. So, I can catch Quit-events and know if Word is alive or not - should now ;)

        Event monitoring in Excel I still haven't solved nor got an answer to. What I did to find out if Excel is still alive is a simple workaround:

        public boolean isAlive(){
          try{
            Dispatch.get( excelDisp, "Visible");
            return true;
          } catch (Exception e) {
            return false;
          }
        }

        I simply try to invoke the visible command on the excel object. If the call fails I assume Excel to be not alive. As
        an extra check I have implemented this also for Word.

        Hope this helps. If anyobne finds a propper solution for Excel, I'd be happy to hear of it.

        Teletobi

         
        • Jorge von Rudno

          Jorge von Rudno - 2009-07-17

          Hallo teletobi,

          I have the same problem as you when i want to check if excel is open. Did you a solution found?

          I was tring to implement your sugestion, but i have a question:
          public boolean isAlive(){
          try{
          Dispatch.get( excelDisp, "Visible");
          return true;
          } catch (Exception e) {
          return false;
          }
          }

          is  "excelDisp" an object " ActiveXCompont? or how must i define this varable? something like:
          excelDisp = new ActiveXComponent("Excel.Application");

          thak you very much for your support.

          Regards

          Jorge

           
    • Veera

      Veera - 2005-03-01

      Thanks for the reply.

      I was able to get events generated for Word.

      I tried doing the same for Excel and the code failed when called

      ActiveXComponent excelComponent = new ActiveXComponent("Excel.Application");

      Object excelObject = excelComponent.getObject();

      DispatchEvents de = new DispatchEvents((Dispatch)excelObject, excelEvent);

      it is throwing
      "couldn't get IProvideClassInfo
      com.jacob.com.ComFailException: Can't find event iid"
      exception. I think for Excel we need to handle events in a different way. I will try to do some more research and will let you know.

       
      • Teletobi

        Teletobi - 2005-03-02

        Hi,

        that's the same what I experienced. I did some exploring inside the C++ code and found that JACOB tries to find a propper TypeLib in the Windows registry. For Word the searched key exists but not for Excel.
        The Excel TypeLib lays within the excel.exe, I tried a little with it but with no success.

        Regards,
        Teletobi

         
        • Julien

          Julien - 2006-11-09

          Hi,

          I'm trying to catch event from Excel by using DispathEvents :

          public class JacobTest
          {

            public static void main(String[] args)
            {
              ComThread.InitSTA();  
             
              ActiveXComponent xl = new ActiveXComponent("Excel.Application");
              try {
                DispatchEvents o2DispatchEvents = new DispatchEvents((Dispatch)
                    xl,new ExcelEventHandler());

               
                Thread.sleep(100000);

              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                xl.invoke("Quit", new Variant[] {});
                ComThread.Release();
              }

            }
           
            static public class ExcelEventHandler
            {
             
            }
          }

          but I have the following exception.

          com.jacob.com.ComFailException: Can't find event iid
              at com.jacob.com.DispatchEvents.init3(Native Method)
              at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:114)
              at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:84)
              at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:70)
              at com.density.test.excel.JacobTest.main(JacobTest.java:31)
          GetEventIID: couldn't get IProvideClassInfo

          Has someone found a solution since the last post of this thread in 2005 ?

          Thanks,
          Julien.

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.