文件,直接展示就容易很多,经过研究,果然可以做
到,步骤如下:
第一步 下载
jacob
下载地址: http://www.chinait8.net/download/ide/4107.html
第二步 解压下载的文件,将其中
jacob.jar 放入
项目的
库中。
第三步 复制以下方法到任意类中。
public boolean transWord2Htm(String docFile) {
String HtmlFile = docFile.substring(0, (docFile.length() - 4)) + ".htm";
ActiveXComponent app = new ActiveXComponent("Word.Application");
try {
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docFile, new
Variant(false),new Variant(true) }, new int[1]).toDispatch();
// 打开
文件
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {HtmlFile, new Variant(8)}, new
int[1]);
// 作为
格式保存文件
Dispatch.call(doc, "Close", new Variant(false));
} catch (Exception e) {
e.printStackTrace();
return false;
评论7