需要下载几个jar包:
goto http://sourceforge.net/projects/jacob-project/ and download latest library of jacob.
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);
}
}