免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1915 | 回复: 0
打印 上一主题 下一主题

利用jacob将MS Word文档转换成Html [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-02 14:01 |只看该作者 |倒序浏览
利用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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP