zoukankan      html  css  js  c++  java
  • jacob将word转换为html

    1.导包jacob.jar

       

    2.将下面两个文件复制到C:WindowsSystem32路径下

                      

     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)Javajdk1.7.0_55jrein

         

     

     

     

     

     

     

  • 相关阅读:
    photoshop--图像大小(分辨率和宽高)
    Arduino--单向倾斜开关
    禁止google浏览器http链接强制跳转为https
    属性缓存_使用ConcurrentDictionary替代Hashtable对多线程的对象缓存处理
    .Net(windows服务器)清理缓存数据的几个方法
    【西天取经】(升级.net5)用了一整天才把项目从.netcoreapp3.1升级到.net5(转载)
    在Debian 9 vim中启用鼠标复制粘贴
    将数据批量插入SQL Server
    shell 脚本中 在grep -E '($wo|$ni|$ta)' 这里面用变量
    kubernetes 重启的几种方法
  • 原文地址:https://www.cnblogs.com/fjkgrbk/p/jacob_word-html.html
Copyright © 2011-2022 走看看