- 论坛徽章:
- 0
|
利用jacob将word转换成html,服务器需要安装office (不能跨平台了,痛苦!! 给Microsoft打工了),需要jacob.dll复制到系统文件夹内。
/**
* 作者:张广军
*
* 创建日期 2005-3-22
*/
package com.leader.dxoa.attach;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/**
* 说明:MsOffice 转换成 Html
*
* @author Building
*
*/
public class OfficeToHtml {
private final static ActiveXComponent component = new ActiveXComponent(
"Word.Application");
/**
* MsWord转换成Html
*
* @param ls_word
* Word文件名
* @param ls_html
* Html文件名
* @return boolean 成功=True 失败=False
*/
public boolean word2html(String ls_word, String ls_html) {
boolean lb_return = true;
try {
Dispatch wordacc = component.getProperty("Documents").toDispatch();
Dispatch wordfile = Dispatch.invoke(
wordacc,
"Open",
Dispatch.Method,
new Object[] { ls_word, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(wordfile, "SaveAs", Dispatch.Method, new Object[] {
ls_html, new Variant(8) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call((Dispatch) wordfile, "Close", (Object) f);
} catch (Exception e) {
e.printStackTrace();
lb_return = false;
} finally {
component.invoke("Quit", new Variant[] {});
}
return lb_return;
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5035/showart_19058.html |
|