把world转成html

本来用php转的 效果不太理想 很不稳定

最后试了下java 效果不错 只记录java的方法好了 其实他们的原理都是一样的啊,都是用到了微软的com

首先是准备工作 

下载(明确dll的版本是64位的还是32位的)

把jar导入项目 把dll放入jdk的bin目录下 ok

package word2html;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComException;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class word2html {

    
        
    public static boolean wordToHtml(String inPath, String toPath) {  
        // 启动word  
        ActiveXComponent axc = new ActiveXComponent("Word.Application");  
  
        boolean flag = false;  
  
        try {  
            // 设置word不可见  
            axc.setProperty("Visible", new Variant(false));  
  
            Dispatch docs = axc.getProperty("Documents").toDispatch();  
  
            // 打开word文档  
            Dispatch doc = Dispatch.invoke(  
                    docs,  
                    "Open",  
                    Dispatch.Method,  
                    new Object[] { inPath, new Variant(false),  
                            new Variant(true) }, new int[1]).toDispatch();  
  
            // 作为html格式保存到临时文件  
            Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {  
                    toPath, new Variant(8) }, new int[1]);  
  
            Variant f = new Variant(false);  
            Dispatch.call(doc, "Close", f);  
            flag = true;  
            return flag;  
  
        } catch (Exception e) {  
            e.printStackTrace();  
            return flag;  
        } finally {  
            axc.invoke("Quit", new Variant[] {});  
        }  
    }  
  
    public static void main(String[] args) {  
          
    word2html.wordToHtml("D://123.docx","D://123.htm");  
  
    }  

    

    
}

然后是效果图

然后问题来了,怎么把生成好的html做成文章

1、文章名要有意义

2、按时间遍历静态的html,然后把他们的名字列出来,这是文章列表页

3、点击查看要能看到文章详情,就不是传id了,而是传文章路径

4、点击了文章路径肯定是能看到文章的

5、怎么显示为手机页呢?这就需要把页面包涵进来,用正则进行处理一下。

原文地址:https://www.cnblogs.com/hellowzd/p/5017388.html