Package com.jacob.com

Examples of com.jacob.com.Dispatch


        .invoke("ExecQuery", new Variant(query));

    EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());

    String resultString = "";
    Dispatch item = null;

    while (enumVariant.hasMoreElements()) {
      resultString = "";
      item = enumVariant.nextElement().toDispatch();
      String categoryString = Dispatch.call(item, "CategoryString")
View Full Code Here


   * ----------------------------------------------------------------------------------------------------------------------------
   */
  public void testLeakWithSetString() {

    ActiveXComponent xl = null;
    Dispatch workbooks = null;
    Dispatch workbook = null;
    Dispatch workSheets = null;
    Dispatch sheet = null;
    Dispatch tabCells = null;
    SafeArray sa = null;

    // -Dcom.jacob.autogc=true
    System.out.println("Jacob version: " + JacobReleaseInfo.getBuildVersion());

    for (int t = 0; t < 10; t++) {
      // look at a large range of cells
      String position = "A7:DM8934";

      try {
        xl = new ActiveXComponent("Excel.Application");
        System.out
            .println("Excel version=" + xl.getProperty("Version"));

        xl.setProperty("Visible", new Variant(false));
        workbooks = xl.getProperty("Workbooks").toDispatch();

        workbook = Dispatch.get(workbooks, "Add").toDispatch();

        workSheets = Dispatch.get(workbook, "Worksheets").toDispatch();

        sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
        // grab the whole range specified above.
        tabCells = Dispatch.invoke(sheet, "Range", Dispatch.Get,
            new Object[] { position }, new int[1]).toDispatch();

        sa = Dispatch.get(tabCells, "Value").toSafeArray(true);

        System.out.println("Ub0=" + sa.getUBound(1)); // nbCol
        System.out.println("Ub1=" + sa.getUBound(2)); // nbLgn

        // number of rows
        int nbLgn = sa.getUBound(2);
        // number of columns
        int nbCol = sa.getUBound(1);

        int[] colLgn = new int[] { 0, 0 };

        // now set a value on every cell in the range we retrieved
        for (int i = 1; i <= nbLgn; i++) {
          colLgn[1] = i;

          for (int j = 1; j <= nbCol; j++) {
            colLgn[0] = j;
            // this one works with out a leak 1.13-M3
            // sa.setString(j, i, "test");
            // This one leaks with 1.13-M3 and earlier
            sa.setString(colLgn, "test");
          }
        }

        Dispatch.put(tabCells, "Value", sa);

        Variant f = new Variant(false);
        Dispatch.call(workbook, "Close", f);
        System.out.println("Close");
      } catch (Exception e) {
        e.printStackTrace();
      } finally {

        if (sa != null) {
          try {
            sa.safeRelease();
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            sa = null;
          }
        }

        if (tabCells != null) {
          try {
            tabCells.safeRelease();
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            tabCells = null;
          }
View Full Code Here

      // put the variant in the array
      sa.setVariant(0, v);

      // take it back out
      Variant v2 = sa.getVariant(0);
      Dispatch d = v2.toDispatch();

      // make sure you can call eval on it
      result = Dispatch.call(d, "Eval", scriptCommand);
      assertTrue(result.toString().equals("6"));
    } catch (ComException e) {
View Full Code Here

   * behavior if someone hits the cancel button
   *
   */
  public void testPrintDialog() {
    ActiveXComponent oActiveX = new ActiveXComponent("Visio.Application");
    Dispatch oDocuments = oActiveX.getProperty("Documents").toDispatch();
    // create a blank document
    Dispatch.call(oDocuments, "Add", "");
    try {
      Dispatch.call(oActiveX, "DoCmd", new Integer(1010)).getInt();
      System.out.println("User hit the ok button.");
View Full Code Here

    // Create a Dispatch Parameter to hide the document that is opened
    Dispatch.put(wordObject, "Visible", new Variant(false));

    // Instantiate the Documents Property
    Dispatch documents = objWord.getProperty("Documents").toDispatch();

    // Open a word document, Current Active Document
    document = Dispatch.call(documents, "Open", filename).toDispatch();
  }
View Full Code Here

    ActiveXComponent xl = new ActiveXComponent("Excel.Application");
    try {
      System.out.println("version=" + xl.getProperty("Version"));
      System.out.println("version=" + Dispatch.get(xl, "Version"));
      Dispatch.put(xl, "Visible", new Variant(true));
      Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
      Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
      Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
      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();
      Dispatch.put(a1, "Value", "123.456");
      Dispatch.put(a2, "Formula", "=A1*2");
      System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
      System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
View Full Code Here

   * written
   */
  public void runTest() {
    // deprecated
    // System.runFinalizersOnExit(true);
    Dispatch test = new ActiveXComponent("MathTest.Math");
    TestEvents te = new TestEvents();
    DispatchEvents de = new DispatchEvents(test, te);
    if (de == null) {
      System.out
          .println("null returned when trying to create DispatchEvents");
View Full Code Here

  private static void recurseFolders(int iIndent, Dispatch o) {

    if (o == null) {
      return;
    }
    Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
    // System.out.println("oFolders=" + oFolders);
    if (oFolders == null) {
      return;
    }

    Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
    do {
      Object oFolderName = Dispatch.get(oFolder, "Name");
      if (null == oFolderName) {
        break;
      }
View Full Code Here

    ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
    try {
      System.out.println("version=" + axOutlook.getProperty("Version"));

      Dispatch oOutlook = axOutlook.getObject();
      System.out.println("version=" + Dispatch.get(oOutlook, "Version"));

      Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
      System.out.println("oNameSpace=" + oNameSpace);

      recurseFolders(0, oNameSpace);

    } finally {
View Full Code Here

      // I am now dealing with the default interface (IFace1)
      Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
      System.out.println(Dispatch.get(mf, "Face1Name"));

      // get to IFace2 through the IID
      Dispatch f2 = mf
          .QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
      // I am now dealing with IFace2
      Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
      System.out.println(Dispatch.get(f2, "Face2Nam"));

      // get to IFace3 through the IID
      Dispatch f3 = mf
          .QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
      // I am now dealing with IFace3
      Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
      System.out.println(Dispatch.get(f3, "Face3Name"));
View Full Code Here

TOP

Related Classes of com.jacob.com.Dispatch

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.