jacob操作window office文档

jacob操作window office文档


使用前操作
    1、把dll文件放在%JAVA_HOME%\bin下(注意系统是32位还是64位),也可以放在C:\Windows\System32下,如果是64位应该放在C:\Windows\SysWOW64 下。建议放在jdk的bin目录下
    2、如果是在eclipse下开发,需要重新引入jdk(Preference/Java/Installed JREs)
    3、开发时将jacab.jar包放在项目lib下并add到liabraries中即可。


测试代码:

                System.out.println("Jacob测试开始");
		String anotherDocPath = "d:\\test.xls";
		String saveAsPath = "d:\\testx.xls";
		ActiveXComponent excel = new ActiveXComponent("Excel.Application");
		excel.setProperty("Visible", new Variant(false)); 
		Dispatch documents = excel.getProperty("Workbooks").toDispatch(); 
		
		Dispatch excel2 = Dispatch.call(documents, "Open", anotherDocPath).toDispatch();
		
		Dispatch.call(excel2, "SaveAs", saveAsPath);
		Dispatch.call(excel2, "Close", new Variant(true));
		
		Dispatch.call(excel, "Quit");
		System.out.println("Jacob测试结束");

jacob下载地址:

    http://download.csdn.net/detail/tandaly/7213323

你可能感兴趣的:(jacob)