jacob是java和windows下的com橋,通過它我們可以在java程序中調(diào)用com組件。如果你的jdk是1.4,那你需要下載jacob1.9的jni庫才能正常運(yùn)行,早期版本在jdk1.4下有些問題。
以下是引用片段:
package com;
/**
* 〈p〉title:word文檔轉(zhuǎn)html類〈/p〉
* 〈p〉description: 〈/p〉
* 〈p〉copyright:() 2002〈/p〉
* @author 舵手
* @version 1.0
*/
import com.jacob.com.*;
import com.jacob.activex.*;public class wordtohtml {
/**
*文檔轉(zhuǎn)換函數(shù)
*@param docfile word文檔的絕對(duì)路徑加文件名(包含擴(kuò)展名)
*@param htmlfile 轉(zhuǎn)換后的html文件絕對(duì)路徑和文件名(不含擴(kuò)展名)
*/
public static void change(string docfile, string htmlfile) {
activexcomponent app = new activexcomponent("word.application"); // 啟動(dòng)word
try {
app.setproperty("visible", new variant(false));
//設(shè)置word不可見
object docs = app.getproperty("documents").todispatch();
object doc = dispatch.invoke(docs,"open",dispatch.method,new object[]
{ docfile, new variant(false),new variant(true) }, new int[1]).todispatch();
// 打開word文件
dispatch.invoke(doc, "saveas", dispatch.method, new object[] {htmlfile,
new variant(8) }, new int[1]);
// 作為html格式保存到臨時(shí)文件
variant f = new variant(false);
dispatch.call(doc, "close", f);
} catch (exception e) {
e.printstacktrace();
} finally {
app.invoke("quit", new variant[]{});
}
}
public static void main(string[] strs){
wordtohtml.change("c:/a/運(yùn)輸管理調(diào)度系統(tǒng)總體方案.doc", "c:/a/t");}
}
新聞熱點(diǎn)
疑難解答
圖片精選