PHP java word 转 html

    xiaoxiao2021-03-25  102

    php 版本 

    function word2html($wordname,$htmlname)   

     {     $word = new COM("word.application"or die("Unable to instanciate Word");     $word->Visible = 1;     $word->Documents->Open($wordname);     $word->Documents[1]->SaveAs($htmlname,8);     $word->Quit();     $word = null;     unset($word);     }        word2html('D:/www/test/6.docx','D:/www/test/6.html');    效果不是很好 ,源码不叫乱,不建议使用。仅供了解,知道有这么个东东

    查看PHP.ini中是否已经开启了com.allow_dcom = true

    从php/ext/里面查找一下有没有这个php_com_dotnet.dll这个文件

    如果没有网上下载个,一般都会有的吧应该大概可能。。

    然后查找这个php.ini里面查找下#extension=php_com_dotnet.dll把前面的#号去掉

    如果找不到就复制,手动添加一下

    在线转换地址 不过得自己核查一遍 比上面的方法 源码容易修改(也不是好办法) http://www.docpe.com/word/word-to-html.aspx 继续走索好办法 java 版本

    到官网下载Jacob,地址链接:http://sourceforge.net/projects/jacob-project/

    2、将压缩包解压后,Jacob.jar添加到Libraries中(先复制到项目目录中,右键单击jar包选择Build Path—>Add to Build Path);

    3、将Jacob.dll放至当前项目所用到的“jre\bin”下面 有 32 64 位 ,根据自己系统决定

    package com.finn; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class DomToHtml { public static final int WORD_HTML = 8; public static void main(String[] args) { // TODO Auto-generated method stub String docfile = "C:\\Users\\wen\\Desktop\\htmldoc\\aaa.docx";           String htmlfile = "C:\\Users\\wen\\Desktop\\htmldoc\\aaa.html";           DomToHtml.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("*****转换完毕********");       }   }
    转载请注明原文地址: https://ju.6miu.com/read-14273.html

    最新回复(0)