首页 > 开发 > Java > 正文

Java程序把Word文档直接转换成HTML文件

2024-07-13 09:55:07
字体:
来源:转载
供稿:网友
  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"); // 启动wordtry {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"); }}

最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表