Java中把word文档转换成为html格式

来源:互联网 发布:2017院士 知乎 编辑:程序博客网 时间:2024/06/02 14:58

需要下载几个jar包:

goto http://sourceforge.net/projects/jacob-project/ and download latest library of jacob.

     import com.jacob.activeX.ActiveXComponent;  
import com.jacob.com.Dispatch;  
import com.jacob.com.Variant;  
public class Test {  
    public static void main(String[] args) {  
        ActiveXComponent app = new ActiveXComponent("Word.Application");  
        app.setProperty("Visible", new Variant(false));  
        Dispatch doc1 = app.getProperty("Documents").toDispatch();  
        //打开《离散数学》(64)刘建元.doc  
        Dispatch doc2 = Dispatch.invoke(  
            doc1,   
            "Open",   
            Dispatch.Method,  
            new Object[]{"D://《离散数学》(64)刘建元.doc", new Variant(false), new Variant(true)},  
            new int[1]  
        ).toDispatch();  
        //另存为《离散数学》(64)刘建元.html  
        Dispatch.invoke(  
            doc2,  
            "SaveAs",   
            Dispatch.Method,   
            new Object[]{  
                "D://《离散数学》(64)刘建元 .html",   
                new Variant(8)//7为txt格式, 8保存为html格式  
            },   
            new int[1]  
        );  
        Variant f = new Variant(false);  
        Dispatch.call(doc2, "Close", f);  
    }  
}

0 0
原创粉丝点击