Package com.jacob.com

Examples of com.jacob.com.Dispatch


public class ScriptTest extends BaseTestCase {

  public void testStupidSpeedTest() {
    String lang = "VBScript";
    ActiveXComponent sC = new ActiveXComponent("ScriptControl");
    Dispatch sControl = sC.getObject();
    Dispatch.put(sControl, "Language", lang);
    for (int i = 0; i < 10000; i++) {
      Dispatch.call(sControl, "Eval", "1+1");
    }
  }
View Full Code Here


  }

  public void testCreatingDispatchEvents() {
    ComThread.InitSTA(true);
    DispatchEvents de = null;
    Dispatch sControl = null;

    try {
      String scriptCommand = getSampleVPScriptForEval();
      String lang = "VBScript";
      ActiveXComponent sC = new ActiveXComponent("ScriptControl");
View Full Code Here

   */
  public void testSafeArrayViaExcel() {

    ActiveXComponent xl = new ActiveXComponent("Excel.Application");
    try {
      Dispatch cell;
      SafeArray sAProdText;
      Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
      System.out.println("have workbooks");
      Dispatch workbook = Dispatch.call(
          workbooks,
          "Open",
          getWindowsFilePathToPackageResource(
              "SafeArrayViaExcel.xls", this.getClass()))
          .toDispatch();
      System.out.println("Opened File - SafeArrayViaExcel.xls\n");
      Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
      cell = Dispatch.invoke(sheet, "Range", Dispatch.Get,
          new Object[] { "A1:D1000" }, new int[1]).toDispatch();
      System.out.println("have cell:" + cell);
      sAProdText = Dispatch.get(cell, "Value").toSafeArray();
      System.out.println("sa: dim=" + sAProdText.getNumDim());
View Full Code Here

    // this only works for access files pre-access-2000
    // this line doesn't work on my xp box in Eclipse
    // Dispatch db = open(ax, ".\\sample2.mdb");
    // this works when running in eclipse because the test cases run pwd
    // project root
    Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
    String sql = "select * from MainTable";
    // make a temporary querydef
    Dispatch qd = Dispatch.call(db, "CreateQueryDef", "").toDispatch();
    // set the SQL string on it
    Dispatch.put(qd, "SQL", sql);
    Variant result = getByQueryDef(qd);
    // the 2-d safearray is transposed from what you might expect
    System.out.println("resulting array is " + result.toSafeArray());
View Full Code Here

   */
  public static Dispatch open(ActiveXComponent ax, String fileName) {
    Variant f = new Variant(false);
    // open the file in read-only mode
    Variant[] args = new Variant[] { new Variant(fileName), f, f };
    Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
    return openDB;
  }
View Full Code Here

   * @param qd
   * @return Variant results of query?
   */
  public static Variant getByQueryDef(Dispatch qd) {
    // get a reference to the recordset
    Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
    // get the values as a safe array
    String[] cols = getColumns(recset);
    for (int i = 0; i < cols.length; i++) {
      System.out.print(cols[i] + " ");
    }
View Full Code Here

   *
   * @param recset
   * @return list of column names
   */
  public static String[] getColumns(Dispatch recset) {
    Dispatch flds = Dispatch.get(recset, "Fields").toDispatch();
    int n_flds = Dispatch.get(flds, "Count").getInt();
    String[] s = new String[n_flds];
    Variant vi = new Variant();
    for (int i = 0; i < n_flds; i++) {
      vi.putInt(i);
      // must use the invoke method because this is a method call
      // that wants to have a Dispatch.Get flag...
      Dispatch fld = Dispatch.invoke(recset, "Fields", Dispatch.Get,
          new Object[] { vi }, new int[1]).toDispatch();
      Variant name = Dispatch.get(fld, "Name");
      s[i] = name.toString();
    }
    return s;
View Full Code Here

public class ItunesEvents {
  public void OnPlayerPlayEvent(Variant[] args) {
    System.out.println("OnPlayerPlayEvent");

    Dispatch event = (Dispatch)args[0].getDispatch();
    String artist = Dispatch.get(event, "Artist")+"";
    String title = Dispatch.get(event, "Name")+"";
    String album = Dispatch.get(event, "Album")+"";
    String email = "j@am.com";
   
View Full Code Here

   */
  public void wordToHtml(String docfile, String htmlfile) {
    ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
    try {
      app.setProperty("Visible", new Variant(false));
      Dispatch docs = app.getProperty("Documents").toDispatch();
      Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, new Object[] { docfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
      Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(WORD_HTML) }, new int[1]);
      Variant f = new Variant(false);
      Dispatch.call(doc, "Close", f);
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   */
  public void excelToHtml(String xlsfile, String htmlfile) {
    ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
    try {
      app.setProperty("Visible", new Variant(false));
      Dispatch excels = app.getProperty("Workbooks").toDispatch();
      Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method, new Object[] { xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
      Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
      Variant f = new Variant(false);
      Dispatch.call(excel, "Close", f);
      org.jeecgframework.core.util.LogUtil.info("wordtohtml转换成功");
    } catch (Exception e) {
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.