Java Code Examples for com.jacob.activeX.ActiveXComponent

The following are top voted examples for showing how to use com.jacob.activeX.ActiveXComponent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: document-converter   File: JacobPDFConverter.java   View source code 7 votes vote down vote up
private void word2PDF(String inputFile, String pdfFile) {
  // 打开word应用程序
  ActiveXComponent app = new ActiveXComponent("Word.Application");
  // 设置word不可见
  app.setProperty("Visible", false);
  // 获得word中所有打开的文档,返回Documents对象
  Dispatch docs = app.getProperty("Documents").toDispatch();
  // 调用Documents对象中Open方法打开文档,并返回打开的文档对象Document
  Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true).toDispatch();
  // 调用Document对象的ExportAsFixedFormat方法,将文档保存为pdf格式
  Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, WORD_VALUE);// word保存为pdf格式宏,值为17
  // 关闭文档
  Dispatch.call(doc, "Close", false);
  // 关闭word应用程序
  app.invoke("Quit", 0);
}
 
Example 2
Project: office2pdf   File: Office2pdfHelper.java   View source code 6 votes vote down vote up
public boolean excel2PDF(String inputFile, String pdfFile) {
	try {
		ActiveXComponent app = new ActiveXComponent("Excel.Application");
		app.setProperty("Visible", false);
		Dispatch excels = app.getProperty("Workbooks").toDispatch();
		Dispatch excel = Dispatch.call(excels, "Open", inputFile, false,
				true).toDispatch();
		Dispatch.call(excel, "ExportAsFixedFormat", xlTypePDF, pdfFile);
		Dispatch.call(excel, "Close", false);
		app.invoke("Quit");
		return true;
	} catch (Exception e) {
		return false;
	}

}
 
Example 3
Project: office2pdf   File: Office2pdfHelper.java   View source code 6 votes vote down vote up
public boolean ppt2PDF(String inputFile, String pdfFile) {
	try {
		ActiveXComponent app = new ActiveXComponent(
				"PowerPoint.Application");
		// app.setProperty("Visible", msofalse);
		Dispatch ppts = app.getProperty("Presentations").toDispatch();

		Dispatch ppt = Dispatch.call(ppts, "Open", inputFile, true,// ReadOnly
				true,// Untitled指定文件是否有标题
				false// WithWindow指定文件是否可见
				).toDispatch();

		Dispatch.call(ppt, "SaveAs", pdfFile, ppSaveAsPDF);

		Dispatch.call(ppt, "Close");

		app.invoke("Quit");
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example 4
Project: itunesJacobExample   File: Playlister.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
	System.out.println("Initing...");
	ComThread.InitMTA(true);
	System.out.println("Getting comp...");
	ActiveXComponent iTunesCom = new ActiveXComponent("iTunes.Application");
	Dispatch iTunesController = (Dispatch) iTunesCom.getObject();
	System.out.println("Instantiating...");
	IiTunes itunes = new IiTunes(iTunesController);
	System.out.println("You now have an Itunes...");
	
	IITSourceCollection sourceList = itunes.getSources();

	for (int i = 1; i <= sourceList.getCount(); i++) {
		IITSource s = sourceList.getItem(i);
		System.out.println("Source found:" + s.getName());
		IITPlaylistCollection lists = s.getPlaylists();
		for (int j = 1; j <= lists.getCount(); j++) {
			IITPlaylist pl = lists.getItem(j);
			System.out.println("Playlist found:" + pl.getName());
		}
	}
	// Dispatch.call(iTunesController, "PlayPause");
	ComThread.Release();
}
 
Example 5
Project: shtrih-m   File: TestShowProps.java   View source code 5 votes vote down vote up
public void test01(){
    System.out.println("test01");
    System.out.println("========");
    
    ActiveXComponent drv = new ActiveXComponent("Addin.DRvFR");
    System.out.println("res code = "+drv.getProperty("ResultCode"));
    System.out.println("res code desc = "+drv.getProperty("ResultCodeDescription"));
    
    System.out.println("show properties");
    drv.invoke("ShowProperties");

    System.out.println("res code = "+drv.getProperty("ResultCode"));
    System.out.println("res code desc = "+drv.getProperty("ResultCodeDescription"));
}
 
Example 6
Project: core   File: Requirement.java   View source code 5 votes vote down vote up
@Override
public void setListValuedField(String fieldName, String fieldValue) {
    ActiveXComponent list = createList();
    for (String val : QCRequirement.getFieldValues(fieldValue)) {
        Dispatch.call(list, "Add", val);
        //Dispatch.put(list, "Add", new Integer(1));
    }
    Dispatch.invoke(this, "Field", Dispatch.Put, new Object[] { fieldName,
            list }, new int[2]);
}
 
Example 7
Project: document-converter   File: JacobPDFConverter.java   View source code 5 votes vote down vote up
private void excel2PDF(String inputFile, String pdfFile) {
  ActiveXComponent app = new ActiveXComponent("Excel.Application");
  app.setProperty("Visible", false);
  Dispatch excels = app.getProperty("Workbooks").toDispatch();
  Dispatch excel = Dispatch.call(excels, "Open", inputFile, false, true).toDispatch();
  Dispatch.call(excel, "ExportAsFixedFormat", EXCEL_VALUE, pdfFile);
  Dispatch.call(excel, "Close", false);
  app.invoke("Quit");
}
 
Example 8
Project: document-converter   File: JacobPDFConverter.java   View source code 5 votes vote down vote up
private void ppt2PDF(String inputFile, String pdfFile) {
  ActiveXComponent app = new ActiveXComponent("PowerPoint.Application");
  // app.setProperty("Visible", msofalse);
  Dispatch ppts = app.getProperty("Presentations").toDispatch();
  Dispatch ppt = Dispatch.call(ppts, "Open", inputFile, true, // ReadOnly
      true, // Untitled指定文件是否有标题
      false// WithWindow指定文件是否可见
  ).toDispatch();
  Dispatch.call(ppt, "SaveAs", pdfFile, PPT_VALUE);
  Dispatch.call(ppt, "Close");
  app.invoke("Quit");
}
 
Example 9
Project: xunxian   File: XinNuo.java   View source code 5 votes vote down vote up
/**
 * 校验信诺对象
 * 首先检查是否创建了信诺对象,若是创建了则跳过,没创建则先创建
 */
public void verifyXinNuo(){
	int i=0;
	while(i++<10){
		try {
			Command.activeXinNuo.invoke("WaitOnline");	//检测繁忙程度,判断信诺对象是否创建
			i=100;	//退出循环
		} catch (Exception e) {
			Command.activeXinNuo=new ActiveXComponent("XinNuo.SendData");		//创建信诺自动答题对象,再次创建
		}
	}
	if(i<100){	//小于100,循环中并没有成功过
		new Func.File().log("加载自动答题失败!可尝试关闭软件后重新打开软件");
	}
}
 
Example 10
Project: xunxian   File: Com.java   View source code 5 votes vote down vote up
/**
 * 创建大漠Com对象
 */
public boolean createDmCom(){
	boolean xnx3_result=false;
	try {
		this.activeDm=new ActiveXComponent("dm.dmsoft");		//创建大漠对象
		xnx3_result=true;
	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("创建大漠Com对象时异常捕获:"+e.getMessage());
	}
	return xnx3_result;
}
 
Example 11
Project: xunxian   File: Com.java   View source code 5 votes vote down vote up
/**
 * 创建大兵键鼠Com对象
 */
public boolean createDb_MouseKeyCom(){
	boolean xnx3_result=false;
	try {
		this.activeDb_MouseKey=new ActiveXComponent("DBSoft.DBSoft_MouseKey");
		xnx3_result=true;
	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("创建大兵键鼠Com对象时异常捕获:"+e.getMessage());
	}
	
	return xnx3_result;
}
 
Example 12
Project: xunxian   File: Com.java   View source code 5 votes vote down vote up
/**
 * 创建大兵窗口Com对象
 */
public boolean createDb_WindowCom(){
	boolean xnx3_result=false;
	try {
		this.activeDb_Window=new ActiveXComponent("DBSoft.DBSoft_Window");
		xnx3_result=true;
	} catch (Exception e) {
		e.printStackTrace();
		new Func.File().log("创建大兵窗口Com对象时异常捕获:"+e.getMessage());
	}
	
	return xnx3_result;
}
 
Example 13
Project: xunxian   File: Guard.java   View source code 5 votes vote down vote up
public Guard(ActiveXComponent activeDm) {
	this.activeDm=activeDm;
	this.color=new Color(this.activeDm);
	this.findPic=new FindPic(this.activeDm);
	this.mouse=new Mouse(this.activeDm);
	this.press=new Press(this.activeDm);
	this.sleep=new Sleep();
	this.position=new Position(this.activeDm);
	this.file=new Func.File(this.activeDm);
	
	this.xinNuo=new XinNuo(this.activeDm);
}
 
Example 14
Project: xunxian   File: DaGuaiFunc.java   View source code 5 votes vote down vote up
public DaGuaiFunc(ActiveXComponent activeDm){
	this.activeDm=activeDm;
	
	this.mouse=new Func.Mouse(this.activeDm);
	this.sleep=new Func.Sleep();
	this.findPic=new Func.FindPic(this.activeDm);
	this.findStr=new Func.FindStr(this.activeDm);
	this.lang=new Func.Lang();
	this.file=new Func.File(this.activeDm);
	this.color=new Func.Color(this.activeDm);
	this.press=new Func.Press(this.activeDm);
	this.position=new Func.Position(this.activeDm);
	
	this.guard=new Guard(this.activeDm);
}
 
Example 15
Project: xunxian   File: SaoHuoFunc.java   View source code 5 votes vote down vote up
public SaoHuoFunc(ActiveXComponent active){
	this.activeDm=active;
	this.mouse=new Func.Mouse(this.activeDm);
	this.sleep=new Func.Sleep();
	this.findPic=new Func.FindPic(this.activeDm);
	this.findStr=new Func.FindStr(this.activeDm);
	this.lang=new Func.Lang();
	this.file=new Func.File(this.activeDm);
	this.color=new Func.Color(this.activeDm);
	this.press=new Func.Press(this.activeDm);
	this.message=new Func.Message();
}
 
Example 16
Project: office2pdf   File: Office2pdfHelper.java   View source code 5 votes vote down vote up
public boolean word2PDF(String inputFile, String pdfFile) {
	try {
		// 打开word应用程序
		ActiveXComponent app = new ActiveXComponent("Word.Application");
		// 设置word不可见
		app.setProperty("Visible", false);
		// 获得word中所有打开的文档,返回Documents对象
		Dispatch docs = app.getProperty("Documents").toDispatch();
		// 调用Documents对象中Open方法打开文档,并返回打开的文档对象Document
		Dispatch doc = Dispatch.call(docs, "Open", inputFile, false, true)
				.toDispatch();
		// 调用Document对象的SaveAs方法,将文档保存为pdf格式
		/*
		 * Dispatch.call(doc, "SaveAs", pdfFile, wdFormatPDF
		 * //word保存为pdf格式宏,值为17 );
		 */
		Dispatch.call(doc, "ExportAsFixedFormat", pdfFile, wdFormatPDF // word保存为pdf格式宏,值为17
		);
		// 关闭文档
		Dispatch.call(doc, "Close", false);
		// 关闭word应用程序
		app.invoke("Quit", 0);
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example 17
Project: cooper   File: CSharpClassBuilder.java   View source code 5 votes vote down vote up
@Override
public List<JavaClass> build(AnalyzeData data) {
	if (this.classes == null || this.getConf().getEveryClassBuild()) {
		classes = new ArrayList<JavaClass>();

		// 调用C#代码
		ActiveXComponent builder = new ActiveXComponent("parse.Builder");
		this.classes = (List<JavaClass>) Dispatch.call(builder, "build", new Object[] { classes }).toJavaObject();

		// (new JavaClassRelationCreator(this.getConf())).create(classes);

		this.onClassBuild(classes);
	}
	return this.classes;
}
 
Example 18
Project: autoredistrict   File: ExcelObj.java   View source code 5 votes vote down vote up
ActiveXComponent(String s){
	try{
		rm = new ReleaseManager();
		id = new IDispatch(rm, s);
		if(id == null){
			System.out.println("jcom ex on ActiveXComponent " + s + ": ID IS NULL!!");
		}
		superid = id;
	}
	catch(Exception ex){
		System.out.println("jcom ex on ActiveXComponent " + s + ": " + ex);
		ex.printStackTrace();
	}
}
 
Example 19
Project: tx2x   File: IntermediateTextTreeToWord.java   View source code 5 votes vote down vote up
public void output(File cWordFile, ControlText resultRootText, LongStyleManagerWord lsManager,
		IntermediateTextTreeWalker cTreeWalker) {

	boolean tVisible = Tx2xOptions.getInstance().getBoolean("Visible");
	ActiveXComponent oWord = new ActiveXComponent("Word.Application");
	oWord.setProperty("Visible", new Variant(tVisible));
	Dispatch oDocuments = oWord.getProperty("Documents").toDispatch();
	try {
		Dispatch.call(oDocuments, "Add", cWordFile.getParent() + "\\" + m_sTemplateDoc).toDispatch();
		Dispatch oSelection = oWord.getProperty("Selection").toDispatch();

		// 書き込み
		outputResult(oSelection, resultRootText, lsManager, cTreeWalker);

		// 保存
		Dispatch oDocument = Dispatch.call(oSelection, "Document").toDispatch();
		Dispatch.call(oDocument, "SaveAs2", cWordFile.getAbsolutePath(), 12 /* wdFormatXMLDocument */);

		oWord.setProperty("Visible", new Variant(true));
	} catch (IOException e1) {
		e1.printStackTrace();
	} catch (ComFailException e) {
		System.out.println("---------- error ----------\n" + e.getLocalizedMessage());
		if (e.getLocalizedMessage().indexOf("Description: ファイルが見つかりません。") != -1) {
			System.out.println(cWordFile.getParent() + "\\" + m_sTemplateDoc);
		}
		System.out.println("---------------------------");
	}
}
 
Example 20
Project: KiranALMSel   File: BugFactory.java   View source code 4 votes vote down vote up
public BugFactory(ActiveXComponent almObject)
{
  this.almObject = almObject;
  this.bugFactory = init();
}
 
Example 21
Project: KiranALMSel   File: TestSet.java   View source code 4 votes vote down vote up
public TestSet(ActiveXComponent almObject, Dispatch testSet)
{
  this.almObject = almObject;
  this.testSet = testSet;
}
 
Example 22
Project: KiranALMSel   File: TSTest.java   View source code 4 votes vote down vote up
public TSTest(ActiveXComponent almObject, Dispatch test) {
	this.test = test;
	this.tsTest = init();
}
 
Example 23
Project: KiranALMSel   File: TestSetTreeManager.java   View source code 4 votes vote down vote up
public TestSetTreeManager(ActiveXComponent almObject)
{
  this.almObject = almObject;
  this.testSetTreeManager = init();
}
 
Example 24
Project: KiranALMSel   File: TDConnection.java   View source code 4 votes vote down vote up
public TDConnection(ActiveXComponent almObject, ServerDetails serverDetails) {
  setAlmObject(almObject);
}
 
Example 25
Project: KiranALMSel   File: TDConnection.java   View source code 4 votes vote down vote up
public ActiveXComponent getAlmObject()
{
  return this.almObject;
}
 
Example 26
Project: KiranALMSel   File: TDConnection.java   View source code 4 votes vote down vote up
public void setAlmObject(ActiveXComponent almObject)
{
  this.almObject = almObject;
}
 
Example 27
Project: KiranALMSel   File: TSTestFactory.java   View source code 4 votes vote down vote up
public TSTestFactory(ActiveXComponent almObject, Dispatch testSet) {
	this.testSet = testSet;
	this.tsTestFactory = init();
}
 
Example 28
Project: KiranALMSel   File: TestSetFolder.java   View source code 4 votes vote down vote up
public TestSetFolder(ActiveXComponent almObject, Dispatch testSetFolder) {
	this.almObject = almObject;
	this.testSetFolder = testSetFolder;
}
 
Example 29
Project: shtrih-m   File: ShtrihMJacobDriver.java   View source code 4 votes vote down vote up
/**
 * Конструктор
 * @param progid progid Компонента или null (тогда Addin.DRvFR)
 */
public ShtrihMJacobDriver(String progid){
    if( progid==null )progid = "Addin.DRvFR";
    drv = new ActiveXComponent(progid);
}
 
Example 30
Project: xnx3   File: Com.java   View source code 4 votes vote down vote up
/**
 * 创建dm.dmsoft对象
 * <li>检测dm.dll是否已注册,若是没有注册,则自动注册
 * <li>若是已注册,则创建dm.dmsoft对象
 */
private void initRegisterDll(){
	if(Com.initDll){
		return;
	}
	
	Com.initDll=true;
	activeBean=new ActiveBean();
	String currentDir=Lang.getCurrentJrePath();	//当前项目Jre路径
	
	try {
		ActiveXComponent activeDm=new ActiveXComponent("dm.dmsoft");
		activeBean.setDm(activeDm);		//创建大漠对象
		activeBean.setPlugin365(new ActiveXComponent("Plugin365ID"));	//创建365对象
		this.createSuccess=true;
	} catch (Exception e) {
		e.printStackTrace();
		//检测dm.dll是否放到了C:下
		String dm="C:\\dm.dll";
		if(!FileUtil.exists(dm)){
			this.createSuccess=false;
			FileUtil.inputStreamToFile(this.getClass().getResourceAsStream("dll/dm.dll"), dm);
			SystemUtil.registerDll(dm);
			log.debug(this, "initRegisterDll()", "注册dm.dll完毕");
		}
		
		//检测Plug365New.dll是否放到了C:下
		String plug365="C:\\Plug365New.dll";
		if(!FileUtil.exists(plug365)){
			this.createSuccess=false;
			FileUtil.inputStreamToFile(this.getClass().getResourceAsStream("dll/Plug365New.dll"), plug365);
			SystemUtil.registerDll(plug365);
			log.debug(this, "initRegisterDll()", "注册Plug365New.dll完毕");
		}
		
		try {
			activeBean.setDm(new ActiveXComponent("dm.dmsoft"));		//创建大漠对象
			activeBean.setPlugin365(new ActiveXComponent("Plugin365ID"));	//创建365对象
			log.debug(this, "initDll", "检测到dll未注册,已自动注册完毕");
			this.createSuccess=true;
		} catch (Exception e2) {
			this.createSuccess=false;
			
			e2.printStackTrace();
			if(e2.getMessage().equals("Can't co-create object")){
				System.out.println("检测到dll插件未注册,进行自动注册时出错!报此异常,极大可能是运行的Jar导致的,请下载我们测试好的Jar1.7安装包进行开发调试");
				System.out.println("http://www.xnx3.com/doc/jre1.7.html");
				System.out.println("(如果弹出提示注册...dll文件失败,则你的操作系统注册不了,有极少数的xp、win7的用户电脑注册不了的,可以换台电脑测试)");
			}
			
		}
	}
	
}
 
Example 31
Project: xnx3   File: ActiveBean.java   View source code 4 votes vote down vote up
public ActiveXComponent getDm() {
	return dm;
}
 
Example 32
Project: xnx3   File: ActiveBean.java   View source code 4 votes vote down vote up
public void setDm(ActiveXComponent dm) {
	this.dm = dm;
}
 
Example 33
Project: xnx3   File: ActiveBean.java   View source code 4 votes vote down vote up
public ActiveXComponent getPlugin365() {
	return plugin365;
}
 
Example 34
Project: xnx3   File: ActiveBean.java   View source code 4 votes vote down vote up
public void setPlugin365(ActiveXComponent plugin365) {
	this.plugin365 = plugin365;
}
 
Example 35
Project: core   File: Filter.java   View source code 4 votes vote down vote up
public Filter(ActiveXComponent factory) {
    super(factory.getPropertyAsComponent("Filter"));
}
 
Example 36
Project: core   File: Requirement.java   View source code 4 votes vote down vote up
public ActiveXComponent createList() {
    ActiveXComponent c = new ActiveXComponent("TDApiOle80.List");
    return c;
}
 
Example 37
Project: cjoop-dm   File: DmSoft.java   View source code 4 votes vote down vote up
public DmSoft(){
	dm = new ActiveXComponent("dm.dmsoft");
}
 
Example 38
Project: xunxian   File: Mouse.java   View source code 4 votes vote down vote up
public Mouse(ActiveXComponent active) {
	this.activeDm=active;
}
 
Example 39
Project: xunxian   File: Mouse.java   View source code 4 votes vote down vote up
public Mouse(ActiveXComponent activeDBMouseKey,ActiveXComponent activeDm){
	this.activeDBMouseKey=activeDBMouseKey;
	this.activeDm=activeDm;
}
 
Example 40
Project: xunxian   File: XinNuo.java   View source code 4 votes vote down vote up
public XinNuo(ActiveXComponent activeDm) {
	this.activeDm=activeDm;
	this.lanAnswer=new LanAnswer(this.activeDm);
	verifyXinNuo();
}