Package com.jacob.activeX

Examples of com.jacob.activeX.ActiveXComponent


    ComThread.InitSTA(true);
    try {
      System.out
          .println("This test only works if MS Word is NOT already running");
      String mApplicationId = "Word.Application";
      ActiveXComponent mTryConnectingFirst = ActiveXComponent
          .connectToActiveInstance(mApplicationId);
      if (mTryConnectingFirst != null) {
        mTryConnectingFirst.invoke("Quit", new Variant[] {});
        System.out
            .println("Was able to connect to MSWord when hadn't started it");
      } else {
        System.out
            .println("Correctly could not connect to running MSWord");
      }
      System.out.println("    Word Starting");
      ActiveXComponent mTryStartingSecond = ActiveXComponent
          .createNewInstance(mApplicationId);
      if (mTryStartingSecond == null) {
        System.out.println("was unable to start up MSWord ");
      } else {
        System.out.println("Correctly could start MSWord");
      }
      ActiveXComponent mTryConnectingThird = ActiveXComponent
          .connectToActiveInstance(mApplicationId);
      if (mTryConnectingThird == null) {
        fail("Was unable able to connect to MSWord after previous startup");
      } else {
        System.out.println("Stopping MSWord");
        // stop it so we can fail trying to connect to a running
        mTryConnectingThird.invoke("Quit", new Variant[] {});
      }
      Thread.sleep(2000);
      ActiveXComponent mTryConnectingFourth = ActiveXComponent
          .connectToActiveInstance(mApplicationId);
      if (mTryConnectingFourth != null) {
        mTryConnectingFourth.invoke("Quit", new Variant[] {});
        fail("Was able to connect to MSWord that was stopped");
      } else {
        System.out
            .println("Correctly could not connect to running MSWord");
      }
View Full Code Here


  public static void main(String[] args) throws Exception {
    ComThread.InitSTA();
    // original test used this
    // ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
    // my xp box with a later release of access needed this
    ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
    // 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
View Full Code Here

    /**
     * Initializes the AutoItX Jacob COM object.
     */
    public AutoItX() {
        autoItX = new ActiveXComponent("AutoItX3.Control");
    }
View Full Code Here

    public boolean finished = false;

    public void run () {
      ComThread.InitMTA(true);

      ActiveXComponent iTunesCom = new ActiveXComponent("iTunes.Application");

      Dispatch iTunesController = (Dispatch)iTunesCom.getObject();

      DispatchEvents events = new DispatchEvents(iTunesController, new ItunesEvents());

      while (!quit) {
        try {
View Full Code Here

   *            WORD文件全路径
   * @param htmlfile
   *            转换后HTML存放路径
   */
  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();
    } finally {
      app.invoke("Quit", new Variant[] {});
    }
  }
View Full Code Here

   *            EXCEL文件全路径
   * @param htmlfile
   *            转换后HTML存放路径
   */
  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) {
      e.printStackTrace();
    } finally {
      app.invoke("Quit", new Variant[] {});
    }
  }
View Full Code Here

     
      if(Settings.os.equals("windows")){
        host = "localhost";
        connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);
        query = "Select * from Win32_Battery";
        axWMI = new ActiveXComponent(connectStr);   
      }
      else { // linux battery, no init action required like windows, but determine which BATx dir
        try {
          //Util.log("Linux batt init", this);
          Process proc = Runtime.getRuntime().exec("ls /proc/acpi/battery");
View Full Code Here

   */
  public static void main(String[] args) {
    String host = "localhost"; //Technically you should be able to connect to other hosts, but it takes setup
    String connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);
    String query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; //Started = 1 means the service is running.
    ActiveXComponent axWMI = new ActiveXComponent(connectStr);
    //Execute the query
                Variant[] vs = {new Variant(query)};
    Variant vCollection = axWMI.invoke("ExecQuery", vs);
   
    //Our result is a collection, so we need to work though the.
    EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
    Dispatch item = null;
    while (enumVariant.hasMoreElements()) {
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.