Java中Office(word/ppt/excel)转换成HTML实现
运行条件: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实现的更多相关文章
- 在Java中导出word、excel格式文件时JSP页面头的设置
我们在JSP中往往会把一些表格里的东西需要导出到本地,一般都是导成word.excel格式的文件.这只需要在JSP页面头设置及在<head></head>标签中添加下面的代码: ...
- Java中如何将字符串数组转换成字符串
如果将“字符串数组”转换成“字符串”,只能通过循环,没有其他方法: public static String getExecSqlString(String str){ StringBuffer sb ...
- Java中为什么long能自动转换成float类型
刷题时候看到一个float和long相互转换的问题,float向long转换的时候不会报错,一个4个字节一个8个字节,通过baidu找到了答案. 下面转载自http://blog.csdn.net/s ...
- Java中如何把一下字符串转换成map
首先,你先确认你的字符串是否是json格式的,如果是json格式,那你可以使用Gson.jar或json-lib-xx-jdk.jar两个包来自动解析解析. 使用Gson更简单些,只需要导入一个包就可 ...
- java中如何将字符串数组转换成字符串(转)
如果是 “字符串数组” 转 “字符串”,只能通过循环,没有其它方法 String[] str = {"abc", "bcd", "def"} ...
- Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享
Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享 在此,先分享下写此文前的经历与感受,我所有的感觉浓缩到一个字,那就是:"坑&qu ...
- word ppt excel文档转换成pdf
1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...
- office(Word、Excel、PPT等图标异常和桌面无新建解决方案)
前言吐槽: 前不久因为安装了WPS,然后觉得不好用卸载WPS装回office就出现了一个很恶心的问题:word文档.excel文档.PPT这些办公软件图标异常,显示的是下面这样: 打开倒是可以正常用w ...
随机推荐
- ASCII码对照表
最近做东西常用到,所以就这里和收藏一下,需要注意的是10和13,在windows中文本java会把回车解释成是1310两个字节,在linux下面是10一个字节. 下面是将两个文件读成了二进制之后的结果 ...
- ubuntu使用备忘
今天在一个古董机子上(03年的)安装了lubuntu14.04,内存512M,奔腾处理器,好像是什么迅驰不支持linux需要的某项技术pae,安装时提示cpu不支持pae,但可以在内核参数中添加for ...
- dedecms /member/reg_new.php SQL Injection Vul
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Dedecms会员中心注入漏洞 2. 漏洞触发条件 http://127 ...
- Flipping Bits in Memory Without Accessing Them: An Experimental Study of DRAM Disturbance Errors
目录 . Rowhammer Introduction . Rowhammer Principle . Track And Fix 1. rowhammer introduction 今天的DRAM ...
- LaTeX 笔记---Q&A
Q: Is it possible to check which package do I need to install to get certain .sty file from tlmgr ra ...
- CF 439C Devu and Partitioning of the Array
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second memory limit per test: ...
- 【Beta】第二次任务发布
后端 了解社区新建文章.添加评论(回复)的机制.整理成API文档,包括如何请求新建文章.新建评论(回复).如何获取文章内容和评论内容. 验收条件:文档PM要能看懂. 前端 微调数据输入部分的布局和操作 ...
- PhyLab2.0设计分析阶段任务大纲(α)
任务概述 由于接手软剑攻城队的PhyLab项目,省去了用户需求分析.团队编码规范.用户界面原型设计和后端逻辑设计的大部分环节,因此前期的主要任务落在了用户使用反馈.功能优化增改方向.用户体验优化以及源 ...
- CF724C: Ray Tracing
传送门 CF的题质量真心不低,这道题的标准解法(应该)是exgcd,打比赛的时候想到了具体的推导公式了,也意识到了需要用exgcd,但是因为寝室要锁门了(其实就是太弱,就放弃了. 首先很显然,这条线所 ...
- JavaScript DES 加密tripledes.js:
<html> <head> <meta http-equiv="content-type" content="text/html; char ...