`
追梦java
  • 浏览: 37263 次
  • 性别: Icon_minigender_1
  • 来自: 南京
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多
 Jacob是Java和Windows下的Com桥,通过它我们可以在Java程序中调用COM组件。如果你的JDK是1.4,那你需要下载Jacob1.9的jni库才能正常运行,早期版本在JDK1.4下有些问题。

以下是引用片段:
packagecom;
/**
*〈p〉Title:Word文档转html类〈/p〉
*〈p〉Description:〈/p〉
*〈p〉Copyright:()2002〈/p〉
*@author舵手
*@version1.0
*/
importcom.jacob.com.*;
importcom.jacob.activeX.*;

publicclassWordtoHtml{
/**
*文档转换函数
*@paramdocfileword文档的绝对路径加文件名(包含扩展名)
*@paramhtmlfile转换后的html文件绝对路径和文件名(不含扩展名)
*/
publicstaticvoidchange(Stringdocfile,Stringhtmlfile){
ActiveXComponentapp=newActiveXComponent("Word.Application");//启动word
try{
app.setProperty("Visible",newVariant(false));
//设置word不可见
Objectdocs=app.getProperty("Documents").toDispatch();
Objectdoc=Dispatch.invoke(docs,"Open",Dispatch.Method,newObject[]
{docfile,newVariant(false),newVariant(true)},newint[1]).toDispatch();
//打开word文件
Dispatch.invoke(doc,"SaveAs",Dispatch.Method,newObject[]{htmlfile,
newVariant(8)},newint[1]);
//作为html格式保存到临时文件
Variantf=newVariant(false);
Dispatch.call(doc,"Close",f);
}catch(Exceptione){
e.printStackTrace();
}finally{
app.invoke("Quit",newVariant[]{});
}
}
publicstaticvoidmain(String[]strs){
WordtoHtml.change("c:\\a\\运输管理调度系统总体方案.doc","c:\\a\\t");

}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics