jacob是java和windows下的com桥,通过它我们可以在java程序中调用com组件。如果你的jdk是1.4,那你需要下载jacob1.9的jni库才能正常运行,早期版本在jdk1.4下有些问题。
| 以下是引用片段: package com; /** * 〈p〉title:word文档转html类〈/p〉 * 〈p〉description: 〈/p〉 * 〈p〉copyright:() 2002〈/p〉 * @author 舵手 * @version 1.0 */ import com.jacob.com.*; import com.jacob.activex.*; public class wordtohtml { /** *文档转换函数 *@param docfile word文档的绝对路径加文件名(包含扩展名) *@param htmlfile 转换后的html文件绝对路径和文件名(不含扩展名) */ public static void change(string docfile, string htmlfile) { activexcomponent app = new activexcomponent("word.application"); // 启动word try { app.setproperty("visible", new variant(false)); //设置word不可见 object docs = app.getproperty("documents").todispatch(); object doc = dispatch.invoke(docs,"open",dispatch.method,new object[] { docfile, new variant(false),new variant(true) }, new int[1]).todispatch(); // 打开word文件 dispatch.invoke(doc, "saveas", dispatch.method, new object[] {htmlfile, new variant(8) }, new int[1]); // 作为html格式保存到临时文件 variant f = new variant(false); dispatch.call(doc, "close", f); } catch (exception e) { e.printstacktrace(); } finally { app.invoke("quit", new variant[]{}); } } public static void main(string[] strs){ wordtohtml.change("c://a//运输管理调度系统总体方案.doc", "c://a//t"); } } |
闽公网安备 35060202000074号