jacob

Java使用Jacob转换Word为HTML

浪子不回头ぞ 提交于 2020-02-28 17:16:42
从今天开始,我也要养成记录开发中遇到的问题和解决方法的好习惯! 最近开发一个Android项目,需要用到查看Word和Pdf文档的功能,由于Android没有直接显示Word和PDF文档的组件,只有一个Webview能查看html网页,所以决定将文档于服务器端转换为html,之后不论是在线预览还是下载到移动终端都可以直接查看了。 最近在网上查阅相关资料,找到利用Jacob来转换Word为html,除了占用CPU性能多一些,好像还不错(.doc和.docx都可以转换的!)。废话不多说,切入正题,这篇文章就先介绍转换Word为html的过程,Pdf还在研究当中,如果有结果我也会发出来! “JACOB一个Java-COM中间件.通过这个组件你可以在Java应用程序中调用COM组件和Win32 libraries。” Ps: Jacob只能用于windows系统,如果你的系统不是windows,建议使用Openoffice.org,这个是跨平台的,虽然我没用,但是应该不麻烦,就是需要先安装Openoffice这个软件,然后使用8100服务。至于Poi,说实话,我真不爱用,那个需要先解析word,然后自己覆写成html,工作量大不说,还得不偿失,因为很难保证转换的html内容的格式与原来word文档格式一致,并且.docx转换也很费劲。 1、到官网下载Jacob,目前最新版是1.17

Java调用 .NET dll

こ雲淡風輕ζ 提交于 2020-02-25 16:07:17
最近接了个蛋疼的活儿,用java调用c# 写的dll 模块,实现一个功能。研究了一下,找到JACOB和JNI4NET两个解决方法。虽然JNI4NET还可以实现 .NET 调用java,不过因为JACOB整个过程比较简单,而且JNI4NET已经很久不维护了,所以还是选择了JACOB。下面简单记录一下流程。 首先下载JACOB,可以在如下地址下载 https://sourceforge.net/projects/jacob-project/ 下载后得到如下几个文件 因为我机器上用的64位java,所以后面的程序默认都是64位,不管是java还是c#。而且所有程序,包括VS的运行均通过管理员账户运行。 创建C# 类库工程,代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Jacob_NET { public interface IClass1 { string getStr(string str); } public class Class1 : IClass1 { public string getStr(string str) { char[] tmp = str

Java Desktop.browse occasionally returning “requested lookup key not found in any active activation context”

↘锁芯ラ 提交于 2020-01-25 09:45:13
问题 I am really struggling with this issue as it seems to occur randomly for me. When I call, Desktop.browse("some url"); Internet Explorer will not display. The exception message is as follows, The requested lookup key was not found in any active activation context. When it occurs it occurs consistently until I restart the machine, but it eventually occurs again. The workstations that seem to have this problem are running Windows XP with Internet Explorer 8 set as the default browser. EDIT: I

JACOB doesn't release the objects properly

狂风中的少年 提交于 2020-01-10 11:45:40
问题 I have an eclipse plugin, which connects to a COM component using Jacob. But after I close the plugin entirely, the .exe file stays hanging in Windows processes. I use ComThread.InitMTA(true) for initialization and make sure that SafeRelease() is called for every COM object I created before closing the app and I call ComThread.Release() at the very end. Do I leave something undone? 回答1: Had the same problem with TD2JIRA converter. Eventually had to patch one of the Jacob files to release the

jacob操作API

点点圈 提交于 2020-01-01 22:01:19
直接上代码,如果对jacob有疑问或出现错误,请查看我这篇文章 jacob一般性错误解决 import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; /** */ /** * * * @author BruceLeey * */ public class MSWordManager { // word文档 private Dispatch doc; // word运行程序对象 private ActiveXComponent word; // 所有word文档集合 private Dispatch documents; // 选定的范围或插入点 private Dispatch selection; private boolean saveOnExit = true ; public MSWordManager() { ComThread.InitSTA(); if (word == null ) { word = new ActiveXComponent( " Word.Application " ); word.setProperty( " Visible " ,

Jacob操作ppt

自作多情 提交于 2020-01-01 21:56:47
前几天使用Apache 的POI操作ppt,后来发现转成的图片出现乱码,而且处理了之后,还会有遗留 因此决定换一种处理方式 Jacob 是 JAVA-COM Bridge的缩写,是一个中间件,能够提供自动化访问MS系统下COM组件和Win32 libraries的功能。 1.准备 (1)安装MS Office (2)使用spring boot 框架 (3)pom.xml 添加 jacob 依赖 <dependency> <groupId>net.sf.jacob-project</groupId> <artifactId>jacob</artifactId> <version>1.14.3</version> </dependency> (4)安装dll 在https://mvnrepository.com/ 查询jacob,选择第一个 选择适合自己机器的dll文件 将下载下来的dll文件放在 C:\Program Files\Java\jdk1.8.0_151\bin C:\Program Files\Java\jdk1.8.0_151\jre\bin C:\WINDOWS\system32 C:\Program Files\Java\jre1.8.0_151\bin 其实只要在 C:\WINDOWS\system32下就可以找到了 2.使用 MS系统提供的COM组件 COM组件

java使用jacob将word转为pdf

放肆的年华 提交于 2019-12-23 18:17:38
word转pdf的方法随便百度一下都是一堆,在此只是想记录一下,方便以后自己查看。 一、在pom文件中引入相应的包: <dependency> <groupId>net.sf.jacob-project</groupId> <artifactId>jacob</artifactId> <version>1.14.3</version> </dependency> 二、在jdk的jre的bin目录下(C:\Program Files\Java\jdk1.8.0_162\jre\bin)引入jacob-1.14.3-x64.dll文件。 三、代码: public class WordToPDFUtil { private static final int wdFormatPDF = 17;//word保存为pdf的格式宏的值是17 public static void wToPdfChange(String wordFile, String pdfFile) {//wordFile word 的路径 //pdfFile pdf 的路径 ActiveXComponent app = null; Dispatch doc = null; try { app = new ActiveXComponent("Word.Application"); /** * app.setProperty(

How to run an Excel personal VBA macro from Java with Jacob

折月煮酒 提交于 2019-12-22 01:27:42
问题 This code runs a macro if it is in the Excel file. It no longer runs a personal macro knowing this macro works fine manually. private static void callExcelMacro(File file, String macroName) { ComThread.InitSTA(); final ActiveXComponent excel = new ActiveXComponent("Excel.Application"); try { // This will open the excel if the property is set to true // excel.setProperty("Visible", new Variant(true)); final Dispatch workbooks = excel.getProperty("Workbooks") .toDispatch(); final Dispatch

Can't co-create object

我们两清 提交于 2019-12-20 02:45:18
问题 i made a dll in .net and call that from java program using jacob.since yesterday i have windows 7 32 bit os so program run successfully.now i formated and install windows 7 64 bit os.so following error encounter: com.jacob.com.ComFailException: Can't co-create object at com.jacob.com.Dispatch.createInstance(Native Method) at com.jacob.com.Dispatch.<init>(Dispatch.java) at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java) at product.Control_product.main(Control_product.java:21)

How do I use a 32 Bit COM object from a 64 bit process?

安稳与你 提交于 2019-12-19 10:57:06
问题 I Use Jacob (JAVA COM Bridge) on a 64 Bit Machine and want to load COM Objects from a 32 bit DLL. How can I do that? 回答1: You will need to host the 32 bit COM object in a 32bit process. So either your entire app will have to run 32bit or youll need to place the COM object in something like COM+ and use cross process calls. 回答2: I solved the problem as follows: Created a small 32 bit out-of-process COM server (.exe) that serves as a factory COM object to create the needed 32 bit objects. So