jacob将word转换为html
1.导包jacob.jar
2.将下面两个文件复制到C:\Windows\System32路径下
3.代码如下
// 8 代表word保存成html
public static final int WORD_HTML = 8;
public static void main(String[] args) {
String docfile = "需要转换的文档的路径";
String htmlfile = "转换完成的路径";
test1.wordToHtml(docfile, htmlfile);
}
/**
* WORD转HTML
* @param docfile WORD文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public static void wordToHtml(String docfile, String htmlfile)
{
// 启动word应用程序(Microsoft Office Word 2003)
ActiveXComponent app = new ActiveXComponent("Word.Application");
System.out.println("*****正在转换...*****");
try
{
// 设置word应用程序不可见
app.setProperty("Visible", new Variant(false));
// documents表示word程序的所有文档窗口,(word是多文档应用程序)
Dispatch docs = app.getProperty("Documents").toDispatch();
// 打开要转换的word文件
Dispatch doc = Dispatch.invoke(
docs,
"Open",
Dispatch.Method,
new Object[] { docfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
// 作为html格式保存到临时文件
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {
htmlfile, new Variant(WORD_HTML) }, new int[1]);
// 关闭word文件
Dispatch.call(doc, "Close", new Variant(false));
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
//关闭word应用程序
app.invoke("Quit", new Variant[] {});
}
System.out.println("*****转换完毕********");
}
4.注意错误
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.18-x86 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:184)
at com.jacob.com.JacobObject.<clinit>(JacobObject.java:110)
at tests.test1.wordToHtml(test1.java:27)
at tests.test1.main(test1.java:16)
没有启动文件
需要在你的jdk文件复制这两个文件到C:\Program Files (x86)\Java\jdk1.7.0_55\jre\bin
jacob将word转换为html的更多相关文章
- 采用jacob实现word转pdf
网络上已经有很多这方面的内容,在用之前也是参考了好多别人的文章,下面记录下我自己的整合过程.整个过程都比较简单: 开发环境:win8 64位系统,在2008下面部署也是一样的. 文档要求jdk的版本要 ...
- 在Ubuntu环境把PPT和Word转换为swf文件
项目需要一个在线浏览文档的功能,于是参照网上的代码写了一份利用Microsoft Office 2010和swftools-2013-04-09-1007.exe转换的程序 思路:调用电脑本机的off ...
- winform实现word转换为PDF(.doc)
注意:实现word转换为PDF文件,本人安装Office为2013; word以后缀为.doc为例实现文件类型转换,具体方式如下所示: 实现步骤: 1.添加命名空间引用——using Microsof ...
- 使用poi将word转换为html
使用poi将word转换为html,支持doc,docx,转换后可以保持文字.表格.图片.样式 演示地址: https://www.xiaoyun.studio/app/preview.html 完整 ...
- Word转换为图片PDF
1. Word转换为PDF,程序很多,但转换后的PDF,还可以复制,虽可以加密禁止复制,但市场上太多的PDF,还可以把PDF转换Word等其他格式,很容易被别人利用和剽窃,即便是PDF加 ...
- jacob 操作word转pdf
项目需要对上传的word及pdf进行在线预览,因基于jquery的pdf插件,很方面实现在线预览,而word实现在线预览费劲不少,于是想到在进行上传处理时,直接将word转成pdf,在预览时直接预览p ...
- C#,VB.NET如何将Word转换为PDF和Text
众所周知,Word是我们日常工作中常用的办公软件之一,有时出于某种需求我们需要将Word文档转换为PDF以及Text.那么如何以C#,VB.NET编程的方式来实现这一功能呢? 下面我将分开介绍如何运用 ...
- 【文件】使用jacob将word转换成pdf格式
使用jacob将word转换成pdf格式 1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...
- Word转换为markdown
Word转换为markdown 首先你的电脑要有office word 1 安装pandoc https://github.com/jgm/pandoc/releases,可以找到最新的pando ...
随机推荐
- sqlserver列重命名
EXEC sp_rename 'tablename.[OldFieldName ]', 'NewFieldName', 'COLUMN'
- 全面解析PHP面向对象的三大特征
PHP面向对象的三大特征: 继承,封装,多态 一.继承 1.如何实现继承? 给子类使用extends关键字,让子类继承父类: class Student extends Person{} 2.实现继承 ...
- 基于JS的文本验证
1,不能为空 <input type="text" onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert(' ...
- Js获取iframe子页面全局变量
项目中通过iframe内嵌了一个子页面,子页面定义了一些全局变量,父页面需要获取子页面的全局变量,做了一些测试(我的环境IE10和Firefox32.0.3),得出如下结论: IE下: window. ...
- Java集合set的并、交、差操作
集合的并.交.差操作 Set<Integer> result = new HashSet<Integer>(); Set<Integer> set1 = new H ...
- 57. Insert Interval (Array; Sort)
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- SSH框架整合思想
--------------------siwuxie095 SSH 框架整合思想 1.SSH 框架,即 Struts2 ...
- 【c++】多层次继承类对象的构造函数参数的传递方法
#include <iostream.h> //基类CBase class CBase { int a; public: CBase(int na) { a=na; cout<< ...
- swift和OC - 拆分数组 和 拆分字符串
1. 拆分数组 /// 根据 数组 截取 指定个数返回 多个数组的集合 func splitArray( array: [Date], withSubSize subSize: Int) -> ...
- [leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List二叉搜索树转有序双向链表
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...