Package com.jacob.activeX

Examples of com.jacob.activeX.ActiveXComponent


  }

  private void comCommand(String cmd) {
    try {
      ComThread.InitMTA(true);
      Dispatch.call(new ActiveXComponent("iTunes.Application").getObject(), cmd);
      ComThread.Release();
    } catch(Throwable t) {
      throw new IllegalStateException(t);
    }
  }
View Full Code Here


   private Dispatch selection;
  
   private boolean saveOnExit = true;
   public Jacob2Word() {
    if (word == null) {
     word = new ActiveXComponent("Word.Application");
     word.setProperty("Visible", new Variant(false));
    }
    if (documents == null)
     documents = word.getProperty("Documents").toDispatch();
   }
View Full Code Here

   * @param args
   */
  public void testPowerpoint() {
    ComThread.InitMTA();

    ActiveXComponent component = new ActiveXComponent(
        "Powerpoint.Application");
    Dispatch comPowerpoint = component.getObject();

    try {
      PowerpointTestThread[] threads = new PowerpointTestThread[NUM_THREADS];
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new PowerpointTestThread(i + 1, comPowerpoint);
View Full Code Here

    String excelApplicationProgramId = "Excel.Application";
    String excelSheetProgramId = "Excel.Sheet";
    String typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";

    // Grab The Component.
    ActiveXComponent axc = new ActiveXComponent(excelApplicationProgramId);
    hookupListener(axc, excelApplicationProgramId, typeLibLocation);

    try {

      System.out.println("version=" + axc.getProperty("Version"));
      System.out.println("version=" + Dispatch.get(axc, "Version"));
      axc.setProperty("Visible", true);
      Dispatch workbooks = axc.getPropertyAsComponent("Workbooks");
      Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
      Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
      hookupListener(sheet, excelSheetProgramId, typeLibLocation);
      Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
          new Object[] { "A1" }, new int[1]).toDispatch();
      Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
          new Object[] { "A2" }, new int[1]).toDispatch();
      System.out.println("Inserting value into A1");
      System.out.println("Inserting calculation 2xA1 into A2");
      Dispatch.put(a1, "Value", "123.456");
      Dispatch.put(a2, "Formula", "=A1*2");
      System.out.println("Retrieved a1 from excel:"
          + Dispatch.get(a1, "Value"));
      System.out.println("Retrieved a2 from excel:"
          + Dispatch.get(a2, "Value"));
      Variant f = new Variant(false);
      Dispatch.call(workbook, "Close", f);
      axc.invoke("Quit", new Variant[] {});

    } catch (ComException cfe) {
      cfe.printStackTrace();
      fail("Failed to attach to " + excelApplicationProgramId + ": "
          + cfe.getMessage());
View Full Code Here

  public void testCaptureWordEvents() {
    String pid = "Word.Application";
    String typeLibLocation = null;

    // Grab The Component.
    ActiveXComponent axc = new ActiveXComponent(pid);
    try {
      // Add a listener (doesn't matter what it is).
      DispatchEvents de;
      if (typeLibLocation == null) {
        de = new DispatchEvents(axc, new WordEventTest());
      } else {
        de = new DispatchEvents(axc, new WordEventTest(), pid,
            typeLibLocation);
      }
      if (de == null) {
        fail("No exception thrown but no dispatch returned for Word events");
      } else {
        // Yea!
        System.out.println("Successfully attached to " + pid);

      }
      // this is different from the ExcelEventTest because it uses
      // the jacob active X api instead of the Dispatch api
      System.out.println("version=" + axc.getPropertyAsString("Version"));
      axc.setProperty("Visible", true);
      ActiveXComponent documents = axc
          .getPropertyAsComponent("Documents");
      if (documents == null) {
        fail("unable to get documents");
      }
      axc.invoke("Quit", new Variant[] {});
View Full Code Here

  public void run() {
    // this used to be 5 seconds but sourceforge is slow
    int delay = 5000; // msec
    // paired with statement below that blows up
    ComThread.InitMTA();
    ActiveXComponent ie = new ActiveXComponent(
        "InternetExplorer.Application");
    try {
      Dispatch.put(ie, "Visible", new Variant(true));
      Dispatch.put(ie, "AddressBar", new Variant(true));
      System.out.println("IETestThread: " + Dispatch.get(ie, "Path"));
      Dispatch.put(ie, "StatusText", new Variant("My Status Text"));

      System.out.println("IETestThread: About to hookup event listener");
      IEEvents ieE = new IEEvents();
      new DispatchEvents(ie, ieE, "InternetExplorer.Application.1");
      System.out.println("IETestThread: Did hookup event listener");
      // / why is this here? Was there some other code here in the past?
      Variant optional = new Variant();
      optional.putNoParam();

      System.out
          .println("IETestThread: About to call navigate to sourceforge");
      Dispatch.call(ie, "Navigate", new Variant(
          "http://sourceforge.net/projects/jacob-project"));
      System.out
          .println("IETestThread: Did call navigate to sourceforge");
      try {
        Thread.sleep(delay);
      } catch (Exception e) {
      }
      System.out.println("IETestThread: About to call navigate to yahoo");
      Dispatch.call(ie, "Navigate", new Variant(
          "http://groups.yahoo.com/group/jacob-project"));
      System.out.println("IETestThread: Did call navigate to yahoo");
      try {
        Thread.sleep(delay);
      } catch (Exception e) {
      }
    } catch (Exception e) {
      threadFailedWithException = e;
      e.printStackTrace();
    } catch (Throwable re) {
      threadFailedWithException = re;
      re.printStackTrace();
    } finally {
      System.out.println("IETestThread: About to send Quit");
      ie.invoke("Quit", new Variant[] {});
      System.out.println("IETestThread: Did send Quit");
    }
    // this blows up when it tries to release a DispatchEvents object
    // I think this is because there is still one event we should get back
    // "OnQuit" that will came after we have released the thread pool
View Full Code Here

  public void run() {
    // this used to be 5 seconds but sourceforge is slow
    int delay = 5000; // msec
    // paired with statement below that blows up
    ComThread.InitMTA();
    ActiveXComponent ie = new ActiveXComponent(
        "InternetExplorer.Application");
    try {
      Dispatch.put(ie, "Visible", new Variant(true));
      Dispatch.put(ie, "AddressBar", new Variant(true));
      System.out.println("IETestActiveProxyThread: "
          + Dispatch.get(ie, "Path"));
      Dispatch.put(ie, "StatusText", new Variant("My Status Text"));

      System.out
          .println("IETestActiveProxyThread: About to hookup event listener");
      IEEventsActiveProxy ieE = new IEEventsActiveProxy();
      new ActiveXDispatchEvents(ie, ieE, "InternetExplorer.Application.1");
      System.out
          .println("IETestActiveProxyThread: Did hookup event listener");
      // / why is this here? Was there some other code here in the past?
      Variant optional = new Variant();
      optional.putNoParam();

      System.out
          .println("IETestActiveProxyThread: About to call navigate to sourceforge");
      Dispatch.call(ie, "Navigate", new Variant(
          "http://sourceforge.net/projects/jacob-project"));
      System.out
          .println("IETestActiveProxyThread: Did call navigate to sourceforge");
      try {
        Thread.sleep(delay);
      } catch (Exception e) {
      }
      System.out
          .println("IETestActiveProxyThread: About to call navigate to yahoo");
      Dispatch.call(ie, "Navigate", new Variant(
          "http://groups.yahoo.com/group/jacob-project"));
      System.out
          .println("IETestActiveProxyThread: Did call navigate to yahoo");
      try {
        Thread.sleep(delay);
      } catch (Exception e) {
      }
    } catch (Exception e) {
      threadFailedWithException = e;
      e.printStackTrace();
    } catch (Throwable re) {
      threadFailedWithException = re;
      re.printStackTrace();
    } finally {
      System.out.println("IETestActiveProxyThread: About to send Quit");
      ie.invoke("Quit", new Variant[] {});
      System.out.println("IETestActiveProxyThread: Did send Quit");
    }
    // this blows up when it tries to release a DispatchEvents object
    // I think this is because there is still one event we should get back
    // "OnQuit" that will came after we have released the thread pool
View Full Code Here

    public boolean OnInit() {
      try {
        System.out.println("OnInit");
        System.out.println(Thread.currentThread());
        String lang = "VBScript";
        sControl = new ActiveXComponent("ScriptControl");

        // sCon can be called from another thread
        sCon = new DispatchProxy(sControl);

        Dispatch.put(sControl, "Language", lang);
View Full Code Here

    }

    public void executaExcelCallBack(String path, String password) {
      // ComThread.InitSTA();
      ComThread.InitMTA();
      ActiveXComponent excel = new ActiveXComponent("Excel.Application");

      try {

        excel.setProperty("Visible", false);
        Dispatch workbooks = excel.getProperty("Workbooks")
            .toDispatch();

        Dispatch workbook = Dispatch.call(workbooks, "Open", path, // FileName
            3, // UpdateLinks
            false, // Readonly
            5, // Format
            password // Password
            ).toDispatch();

        Dispatch sheets = Dispatch.call(workbook, "Worksheets")
            .toDispatch();
        System.out.println("Before executa");
        executa(excel, sheets);
        System.out.println("After executa");

        Dispatch.call(workbook, "Close", new Variant(false));
        Dispatch.call(workbooks, "Close");
        System.out.println("After Close");
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          Thread.sleep(1000);
        } catch (Exception e) {
          e.printStackTrace();
        }
        System.out.println("Before Quit");
        excel.invoke("Quit", new Variant[] {});
        try {
          Thread.sleep(1000);
        } catch (Exception e) {
          e.printStackTrace();
        }
View Full Code Here

import com.jacob.test.BaseTestCase;

public class WMPlayer extends BaseTestCase {

  public void testOpenWMPlayer() {
    ActiveXComponent wmp = null;
    wmp = new ActiveXComponent("WMPlayer.OCX");

    // the sourceforge posting didn't post all the code so this is all we
    // have we need some other information on how to set the document
    // so that we have a url to open
    for (int i = 0; i < 1000; i++) {
      System.out.println("the wmp url is "
          + wmp.getProperty("URL").toString());
    }

  }
View Full Code Here

TOP

Related Classes of com.jacob.activeX.ActiveXComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.