ActiveXComponent app = new ActiveXComponent("Word.Application");
app.setProperty("Visible", new Variant(false));
Dispatch doc1 = app.getProperty("Documents").toDispatch();
//打开aaaa.doc
Dispatch doc2 = Dispatch.invoke(
doc1,
"Open",
Dispatch.Method,
new Object[]{"d://tt.doc", new Variant(false), new Variant(true)},
new int[1]
).toDispatch();
//另存为aaaa.html
String name="aaaa.html";
Dispatch.invoke(
doc2,
"SaveAs",
Dispatch.Method,
new Object[]{
"d://"+name,
new Variant(8)//7为txt格式, 8保存为html格式
},
new int[1]
);
Variant f = new Variant(false);
Dispatch.call(doc2, "Close", f);
File file = new File("d://aaaa.html");
String realPath = ServletActionContext.getServletContext()
.getRealPath("/images");
File filetemp = new File(realPath);
File f1 = new File(filetemp, "aaaa.html");
try {
FileUtils.copyFile(file, f1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
app.setProperty("Visible", new Variant(false));
Dispatch doc1 = app.getProperty("Documents").toDispatch();
//打开aaaa.doc
Dispatch doc2 = Dispatch.invoke(
doc1,
"Open",
Dispatch.Method,
new Object[]{"d://tt.doc", new Variant(false), new Variant(true)},
new int[1]
).toDispatch();
//另存为aaaa.html
String name="aaaa.html";
Dispatch.invoke(
doc2,
"SaveAs",
Dispatch.Method,
new Object[]{
"d://"+name,
new Variant(8)//7为txt格式, 8保存为html格式
},
new int[1]
);
Variant f = new Variant(false);
Dispatch.call(doc2, "Close", f);
File file = new File("d://aaaa.html");
String realPath = ServletActionContext.getServletContext()
.getRealPath("/images");
File filetemp = new File(realPath);
File f1 = new File(filetemp, "aaaa.html");
try {
FileUtils.copyFile(file, f1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
使用jacob-1.17来完成word转换
转换成HTML文件,然后上传到服务器上,通过服务器路径读取出来,显示在页面