您的位置:首页 > 其它

安装 IBM Rational Team Concert Express-C

2011-01-07 12:16 316 查看
第一步:下载得到了jacob.jar

第二步: 将解压后的源代码包中jacob.dll存放到system32目录下。(注:目前比较稳定的版本分别为1.7、1.8、1.9,我用的是1.8版本)

 

 

 

package com.util;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class Jacob2Html {
    public static final int WORD_HTML = 8;
    public static final int PPT_HTML = 12;
    public static final int EXCEL_HTML = 44;
    /**
     * PowerPoint转成HTML
     *
     * @param pptPath
     *            PowerPoint文件全路径
     * @param htmlfile
     *            转换后HTML存放路径
     */
    public static void pptToHtml(String pptPath, String htmlPath) {
       ActiveXComponent offCom = new ActiveXComponent("PowerPoint.Application");
       try {
           offCom.setProperty("Visible", new Variant(true));
           Dispatch excels = offCom.getProperty("Presentations").toDispatch();
           Dispatch excel = Dispatch.invoke(
                  excels,
                  "Open",
                  Dispatch.Method,
                  new Object[] { pptPath, new Variant(false),
                         new Variant(false) }, new int[1]).toDispatch();
           Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
                  htmlPath, new Variant(PPT_HTML) }, new int[1]);
           Variant f = new Variant(false);
           Dispatch.call(excel, "Close");
       } catch (Exception e) {
           e.printStackTrace();
       } finally {
           offCom.invoke("Quit", new Variant[] {});
       }
    }
 
    /**
     * WORD转成HTML
     *
     * @param wordPath
     *            WORD文件全路径
     * @param htmlPath
     *            生成的HTML存放路径
     */
    public static void wordToHtml(String wordPath, String htmlPath) {
       ActiveXComponent offCom = new ActiveXComponent("Word.Application");
       try {
           offCom.setProperty("Visible", new Variant(false));
           Dispatch wordDis = offCom.getProperty("Documents").toDispatch();
           Dispatch doc = Dispatch.invoke(
                  wordDis,
                  "Open",
                  Dispatch.Method,
                  new Object[] { wordPath, new Variant(false),
                         new Variant(true) }, new int[1]).toDispatch();
           Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {
                  htmlPath, new Variant(WORD_HTML) }, new int[1]);
           Variant f = new Variant(false);
           Dispatch.call(doc, "Close", f);
       } catch (Exception e) {
           e.printStackTrace();
       } finally {
           offCom.invoke("Quit", new Variant[] {});
       }
    }
 
    /**
     * EXCEL转成HTML
     *
     * @param xlsfile
     *            EXCEL文件全路径
     * @param htmlfile
     *            转换后HTML存放路径
     */
    public static void excelToHtml(String xlsfile, String htmlfile) {
       ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动word
       try {
           app.setProperty("Visible", new Variant(false));
           Dispatch excels = app.getProperty("Workbooks").toDispatch();
           Dispatch excel = Dispatch.invoke(
                  excels,
                  "Open",
                  Dispatch.Method,
                  new Object[] { xlsfile, new Variant(false),
                         new Variant(true) }, new int[1]).toDispatch();
           Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
                  htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
           Variant f = new Variant(false);
           Dispatch.call(excel, "Close", f);
       } catch (Exception e) {
           e.printStackTrace();
       } finally {
           app.invoke("Quit", new Variant[] {});
       }
    }
}
 

 

 

 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: