Package com.jacob.com

Examples of com.jacob.com.Variant


     */
    public List<String> obterValoresRange(String celulas, Dispatch sheet) {
      List<String> valores = new LinkedList<String>();

      // obtem valor das celulas como um Variant
      Variant var = obterValorCelula(celulas, sheet);

      // toString da Variant � interpretado por um StringTokenizer e os
      // tokens
      // inseridos na lista de retorno
      String arrayAsString = null;
      System.out
          .println("Calling toString() on the Variant that is an array will blow up "
              + var.getvt() + " --> " + arrayAsString);
      arrayAsString = var.toString();
      StringTokenizer st = new StringTokenizer(arrayAsString, "\n");
      while (st.hasMoreTokens()) {
        valores.add(st.nextToken().trim());
      }
      return valores;
View Full Code Here


  public void runMonitor() {

    ActiveXComponent wmi = null;
    wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
    // no connection parameters means to connect to the local machine
    Variant conRet = wmi.invoke("ConnectServer");
    // the author liked the ActiveXComponent api style over the Dispatch
    // style
    ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch());

    // the WMI supports a query language.
    String query = "select CategoryString, Message, TimeGenerated, User, Type "
        + "from Win32_NtLogEvent "
        + "where Logfile = 'Application' and TimeGenerated > '20070915000000.000000-***'";
    Variant vCollection = wmiconnect
        .invoke("ExecQuery", new Variant(query));

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

    String resultString = "";
    Dispatch item = null;

    while (enumVariant.hasMoreElements()) {
View Full Code Here

   * vary in size based on the size of the disk.
   *
   * @return driver total size of the disk
   */
  public String getTotalSize() {
    Variant returnValue = Dispatch.get(myDrive, "TotalSize");
    if (returnValue.getvt() == Variant.VariantDouble) {
      return sizeFormatter.format(returnValue.getDouble());
    } else if (returnValue.getvt() == Variant.VariantInt) {
      return sizeFormatter.format(returnValue.getInt());
    } else {
      return "Don't know type: " + returnValue.getvt();
    }
  }
View Full Code Here

   * in size based on the size of the disk.
   *
   * @return driver free size of the disk
   */
  public String getFreeSpace() {
    Variant returnValue = Dispatch.get(myDrive, "FreeSpace");
    if (returnValue.getvt() == Variant.VariantDouble) {
      return sizeFormatter.format(returnValue.getDouble());
    } else if (returnValue.getvt() == Variant.VariantInt) {
      return sizeFormatter.format(returnValue.getInt());
    } else {
      return "Don't know type: " + returnValue.getvt();
    }
  }
View Full Code Here

    // variant
    System.out.println("Variant");
    SafeArray va = new SafeArray(Variant.VariantVariant, 4);
    System.out.println("elem size:" + va.getElemSize());
    Variant vack[] = new Variant[] { new Variant(1), new Variant(2.3),
        new Variant(true), new Variant("four"), };
    printArray(vack);
    va.fromVariantArray(vack);
    vack = va.toVariantArray();
    printArray(vack);

    Variant v4[] = new Variant[4];
    va.getVariants(0, 4, v4, 0);
    printArray(v4);

    SafeArray va2 = new SafeArray(Variant.VariantVariant, 4);
    va2.setVariants(0, 4, v4, 0);
View Full Code Here

      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 {
View Full Code Here

      String scriptCommand = "1+(2*4)-3";
      String lang = "VBScript";
      ActiveXComponent sControl = new ActiveXComponent("ScriptControl");
      Dispatch.put(sControl, "Language", lang);

      Variant result = Dispatch.call(sControl, "Eval", scriptCommand);
      assertTrue(result.toString().equals("6"));

      // wrap the script control in a variant
      Variant v = new Variant(sControl);

      // create a safe array of type dispatch
      SafeArray sa = new SafeArray(Variant.VariantDispatch, 1);

      // 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

    // Assign a local word object
    wordObject = objWord.getObject();

    // 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
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"));
      Variant f = new Variant(false);
      Dispatch.call(workbook, "Close", f);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      xl.invoke("Quit", new Variant[] {});
View Full Code Here

    DispatchEvents de = new DispatchEvents(test, te);
    if (de == null) {
      System.out
          .println("null returned when trying to create DispatchEvents");
    }
    System.out.println(Dispatch.call(test, "Add", new Variant(1),
        new Variant(2)));
    System.out.println(Dispatch.call(test, "Mult", new Variant(2),
        new Variant(2)));
    Variant v = Dispatch.call(test, "Mult", new Variant(2), new Variant(2));
    // this should return false
    System.out.println("v.isNull=" + v.isNull());
    v = Dispatch.call(test, "getNothing");
    // these should return nothing
    System.out.println("v.isNull=" + v.isNull());
    System.out.println("v.toDispatch=" + v.toDispatch());
  }
View Full Code Here

TOP

Related Classes of com.jacob.com.Variant

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.