运行条件:JDK + jacob.jar + jacob.dll

1) 把jacob.dll在 JAVA_HOME\bin\ 和 JAVA_HOME\jre\bin\ 以及C:\WINDOWS\system32\目录下各放一份
2) 把jacob.jar放入 项目的lib包下,并且在“java构建路径”中也要加载此jar包。
3) 运行项目即可编译通过.

注:jacob.jar以及jacob.dll版本要和jdk版本相匹配,否则可能出现异常!

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*; public class OfficeToHTML { private final static OfficeToHTML oOfficeToHTML = new OfficeToHTML(); public static OfficeToHTML getInstance() {
return oOfficeToHTML;
} public OfficeToHTML() {
} public boolean WordtoHtml(String s, String s1) {
ComThread.InitSTA();
ActiveXComponent activexcomponent = new ActiveXComponent(
"Word.Application");
String s2 = s;
String s3 = s1;
boolean flag = false;
try {
activexcomponent.setProperty("Visible", new Variant(false));
Dispatch dispatch = activexcomponent.getProperty("Documents").toDispatch();
Dispatch dispatch1 = Dispatch.invoke(dispatch, "Open", ,
new Object[] { s2, new Variant(false), new Variant(true) },
new int[]).toDispatch();
Dispatch.invoke(dispatch1, "SaveAs", , new Object[] { s3,
new Variant() }, new int[]);
Variant variant = new Variant(false);
Dispatch.call(dispatch1, "Close", variant);
flag = true;
} catch (Exception exception) {
exception.printStackTrace();
} finally {
activexcomponent.invoke("Quit", new Variant[]);
ComThread.Release();
ComThread.quitMainSTA();
}
return flag;
} public boolean PPttoHtml(String s, String s1) {
ComThread.InitSTA();
ActiveXComponent activexcomponent = new ActiveXComponent(
"PowerPoint.Application");
String s2 = s;
String s3 = s1;
boolean flag = false;
try {
Dispatch dispatch = activexcomponent.getProperty("Presentations")
.toDispatch();
Dispatch dispatch1 = Dispatch.call(dispatch, "Open", s2,
new Variant(-), new Variant(-), new Variant())
.toDispatch();
Dispatch.call(dispatch1, "SaveAs", s3, new Variant());
Variant variant = new Variant(-);
Dispatch.call(dispatch1, "Close");
flag = true;
} catch (Exception exception) {
System.out.println("|||" + exception.toString());
} finally {
activexcomponent.invoke("Quit", new Variant[]);
ComThread.Release();
ComThread.quitMainSTA();
}
return flag;
} public boolean ExceltoHtml(String s, String s1) {
ComThread.InitSTA();
ActiveXComponent activexcomponent = new
ActiveXComponent("Excel.Application");
String s2 = s;
String s3 = s1;
boolean flag = false;
try
{
activexcomponent.setProperty("Visible", new Variant(false));
Dispatch dispatch =
activexcomponent.getProperty("Workbooks").toDispatch();
Dispatch dispatch1 = Dispatch.invoke(dispatch, "Open", , new
Object[] {
s2, new Variant(false), new Variant(true)
}, new int[]).toDispatch();
Dispatch.call(dispatch1, "SaveAs", s3, new Variant());
Variant variant = new Variant(false);
Dispatch.call(dispatch1, "Close", variant);
flag = true;
}
catch(Exception exception)
{
System.out.println("|||" + exception.toString());
}
finally
{
activexcomponent.invoke("Quit", new Variant[]);
ComThread.Release();
ComThread.quitMainSTA();
}
return flag;
} public static void main(String args[]) {
OfficeToHTML otx = OfficeToHTML.getInstance();
boolean flag1 = otx.PPttoHtml("e:/test/test3.pptx", "e:/test/test3.html");
if(flag1){
System.out.println("PPT文件转换成HTML成功!");
}else{
System.out.println("PPT文件转换成HTML失败!");
}
}
}

Java中Office(word/ppt/excel)转换成HTML实现的更多相关文章

  1. 在Java中导出word、excel格式文件时JSP页面头的设置

    我们在JSP中往往会把一些表格里的东西需要导出到本地,一般都是导成word.excel格式的文件.这只需要在JSP页面头设置及在<head></head>标签中添加下面的代码: ...

  2. Java中如何将字符串数组转换成字符串

    如果将“字符串数组”转换成“字符串”,只能通过循环,没有其他方法: public static String getExecSqlString(String str){ StringBuffer sb ...

  3. Java中为什么long能自动转换成float类型

    刷题时候看到一个float和long相互转换的问题,float向long转换的时候不会报错,一个4个字节一个8个字节,通过baidu找到了答案. 下面转载自http://blog.csdn.net/s ...

  4. Java中如何把一下字符串转换成map

    首先,你先确认你的字符串是否是json格式的,如果是json格式,那你可以使用Gson.jar或json-lib-xx-jdk.jar两个包来自动解析解析. 使用Gson更简单些,只需要导入一个包就可 ...

  5. java中如何将字符串数组转换成字符串(转)

    如果是 “字符串数组” 转 “字符串”,只能通过循环,没有其它方法 String[] str = {"abc", "bcd", "def"} ...

  6. Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享

    Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享 在此,先分享下写此文前的经历与感受,我所有的感觉浓缩到一个字,那就是:"坑&qu ...

  7. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  8. JAVA:借用OpenOffice将上传的Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

  9. office(Word、Excel、PPT等图标异常和桌面无新建解决方案)

    前言吐槽: 前不久因为安装了WPS,然后觉得不好用卸载WPS装回office就出现了一个很恶心的问题:word文档.excel文档.PPT这些办公软件图标异常,显示的是下面这样: 打开倒是可以正常用w ...

随机推荐

  1. MySoft.Data 2.7.3版本的GitHub托管(ORM升级封装)

    MySoft.Data 2.7.3 dotnet ORM 版权 这里版权属于老毛:http://www.cnblogs.com/maoyong 说明 MySoft体系中的ORM组件,这里的版本为2.7 ...

  2. 微信公众平台教程和SDK收集

    教程收集: 1.Senparc(.net) http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html 2.方倍工作室 ...

  3. POJ 1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67387   Accepted: 2603 ...

  4. MongoDB安装,配置

    安装 cd /usr/local/srcwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.6.tgztar z ...

  5. ObjC 利用反射和KVC实现嵌套对象序列化成JSON数据

    原理: 0.创建一个新的可变字典:NSMutableDictionary 1.采用class_copyPropertyList函数遍历对象的属性 2.property_getName获取属性名,val ...

  6. nginx中SSI问题的研究

    最近感觉挺爽的,这个项目团队没有一个专门做PHP的,我是第一个进来做PHP(当然还有前端)的,哈哈,我会设计修改出适合我们业务的PHP框架,哈哈,感觉会学到很多东西的样子,前几天在组内20几个前辈面前 ...

  7. Node.js使用Mongoose包操作MongoDB数据库

    1. 安装Mongoose npm install mongoose 2. 使用 2.1 创建连接 var mongoose = require('mongoose'); mongoose.conne ...

  8. tar.xz文件如何解压

    1. tar.xz介绍 XZ压缩最新压缩率之王 xz这个压缩可能很多都很陌生,不过您可知道xz是绝大数linux默认就带的一个压缩工具. 之前xz使用一直很少,所以几乎没有什么提起. 2. 压缩 ta ...

  9. SQLite遇到的关于x64、x86问题

    初次使用SQLite遇到了莫名其妙的问题: 未能加载文件或程序集“System.Data.SQLite, Version=1.0.92.0, Culture=neutral, PublicKeyTok ...

  10. STL之vector

    参考资料:      1.codeproject      2.csdn      3.cplusplus