Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);
new Variant(),这里面的根据传入的参数不同,可以另存为不同的类型,但是在网上搜索了一个并没有找到有关这个参数类型的一个说明,自己尝试了一下,结果如下:
0 | Doc |
1 | Dot |
2-5 | Txt |
6 | Rtf |
7 | Txt |
8、10 | htm |
11 | Xml |
12、16 | Docx |
13 | Docm |
14 | Dotx |
15 | Dotm |
17 | |
代码:
String wordName = reportId + "_report.doc";
response.setHeader("Content-disposition", "attachment;filename="
+ wordName);
response.setContentType("application/msword");
os = response.getOutputStream();
String path = request.getSession().getServletContext()
.getRealPath("/").replace("\\", "/")
+ "temp/word/";
String filePath = path + wordName;
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
fis = new FileInputStream(filePath);
int c;
byte buffer[] = new byte[1024];
while ((c = fis.read(buffer)) != -1) {
os.write(buffer, 0, c);
}