java(word/ppt/excel)转换成HTML实现
来源:互联网 发布:php qq农场游戏源码 编辑:程序博客网 时间:2024/06/05 15:06
- import com.jacob.activeX.ActiveXComponent;
- import com.jacob.com.*;
- public class OfficeToXML {
- private final static OfficeToXML oOfficeToXML = new OfficeToXML();
- public static OfficeToXML getInstance() {
- return oOfficeToXML;
- }
- public OfficeToXML() {
- }
- 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", 1,
- new Object[] { s2, new Variant(false), new Variant(true) },
- new int[1]).toDispatch();
- Dispatch.invoke(dispatch1, "SaveAs", 1, new Object[] { s3,
- new Variant(8) }, new int[1]);
- Variant variant = new Variant(false);
- Dispatch.call(dispatch1, "Close", variant);
- flag = true;
- } catch (Exception exception) {
- exception.printStackTrace();
- } finally {
- activexcomponent.invoke("Quit", new Variant[0]);
- 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(-1), new Variant(-1), new Variant(0))
- .toDispatch();
- Dispatch.call(dispatch1, "SaveAs", s3, new Variant(12));
- Variant variant = new Variant(-1);
- Dispatch.call(dispatch1, "Close");
- flag = true;
- } catch (Exception exception) {
- System.out.println("|||" + exception.toString());
- } finally {
- activexcomponent.invoke("Quit", new Variant[0]);
- 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", 1, new
- Object[] {
- s2, new Variant(false), new Variant(true)
- }, new int[1]).toDispatch();
- Dispatch.call(dispatch1, "SaveAs", s3, new Variant(44));
- 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[0]);
- ComThread.Release();
- ComThread.quitMainSTA();
- }
- return flag;
- }
- public static void main(String args[]) {
- OfficeToXML otx = OfficeToXML.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失败!");
- }
- boolean flag2 = otx.WordtoHtml("e:/test/test2.docx", "e:/test/test2.html");
- if(flag2){
- System.out.println("WORD文件转换成HTML成功!");
- }else{
- System.out.println("WORD文件转换成HTML失败!");
- }
- boolean flag3 = otx.ExceltoHtml("e:/test/test1.xlsx", "e:/test/test1.html");
- if(flag3){
- System.out.println("EXCEL文件转换成HTML成功!");
- }else{
- System.out.println("EXCEL文件转换成HTML失败!");
- }
- }
- }
运行条件:
1.JDK1.6
2.jacob.jar和jacob.dll
1) 把jacob.dll在 ..\Java\jdk1.6.0_10\bin、..\Java\jdk1.6.0_10\jre\bin、C:\WINDOWS\system32 目录下各放一份
2) 把jacob.jar放入 项目的lib包下,并且在“java构建路径”中也要加载此jar包。
3) 运行项目即可编译通过.
注:jacob.jar以及jacob.dll版本一定要和jdk版本相匹配,否则后果自负
0 0
- java(word/ppt/excel)转换成HTML实现
- OFFICE(word/ppt/excel)转换成HTML实现
- OFFICE(word/ppt/excel)转换成HTML实现
- 将PPT&WORD&EXCEL转换成html格式
- 将word、excel、ppt、html、txt转换成图片
- java poi- 实现 word Excel pdf ppt 转 HTML
- java实现word,ppt,excel转pdf
- java实现在线预览--poi实现word、excel、ppt转html
- Word.Excel.ppt转html
- 将word、excel、ppt、html、txt,pdf转换成图片源代码
- java实现爬虫技术,读取txt,word,excel,ppt,pdf,html等格式的文件
- word&excel转换成html
- java使用jacob将word,excel,ppt转成html
- java将Word/Excel/PDF文件转换成HTML整理
- [JAVA]: Jacob 转换Word,Excel为HTML
- Java通过OpenOffice将word、ppt、excel、图片、txt文档转换成PDF
- C#.net word excel powerpoint (ppt) 转换成 pdf
- java实现word,ppt,excel,jpg转pdf
- PhpExcel中文帮助手册|PhpExcel使用方法
- sol资料汇总
- Hibernate自关联(使用注解)
- Android Ubuntu平台下ADB驱动的安装
- Eclipse快捷键总结
- java(word/ppt/excel)转换成HTML实现
- Linux下DDNS客户端的使用
- HTTP POST GET 本质区别详解
- The selected game is missing one or more required ROM or CHD images 解决方法
- 在Android中访问内置SE和基于SE的卡模拟(二) .
- CGContext的基本认识
- 逻辑坐标和设备坐标的区别
- js调用百度地图
- 数据结构笔记-二叉排序树的增删查