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"); }} |