结构:
HSSF - 提供读写Microsoft Excel XLS格式档案的功能。
XSSF - 提供读写Microsoft Excel OOXML XLSX格式档案的功能。
HWPF - 提供读写Microsoft Word DOC97格式档案的功能。
XWPF - 提供读写Microsoft Word DOC2003格式档案的功能。
HSLF - 提供读写Microsoft PowerPoint格式档案的功能。
HDGF - 提供读Microsoft Visio格式档案的功能。
HPBF - 提供读Microsoft Publisher格式档案的功能。
HSMF - 提供读Microsoft Outlook格式档案的功能。
一个简单的下载服务器端的Excel文件到本地
String filepath="文件路径,包括后缀名";
String loadname="下载到本地的文件名,随便起";
String basepath = request.getSession().getServletContext().getRealPath("/");
try {
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(basepath+filepath));
String newfilename=URLEncoder.encode(loadname, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename="+newfilename);
OutputStream ouputStream = response.getOutputStream();
wb.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
注:
response.setContentType( "application/msword" );
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-type","application/pdf");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-type","application/pdf");
1. Content-Type的作用
该实体头的作用是让服务器告诉浏览器它发送的数据属于什么文件类型。
例如:当Content-Type 的值设置为text/html和text/plain时,前者会让浏览器把接收到的实体内容以HTML格式解析,后者会让浏览器以普通文本解析.
2. Content-Disposition 的作用
当Content-Type 的类型为要下载的类型时 , 这个信息头会告诉浏览器这个文件的名字和类型。