怎么在jsp中打开显示excel

2025-03-06 22:05:08
推荐回答(1个)
回答1:

需要导出的文件头上加:
<%@ page contentType="application/vnd.ms-excel" %>
---------------------------------------------------------------
使用OFFice WEB Components
---------------------------------------------------------------
在页首加上<%page contentType="application/vnd.ms-excel"%>
---------------------------------------------------------------


<%//jsp页面代码,只要把下面代码放到页面里就可以了;
response.setContentType("application/unknown;charset=gbk");
response.addHeader("content-disposition","attachment;filename=aaa.xls");%><%'asp 或 asp.net 页面代码,只要把下面代码放到页面里就可以了;
response.ContentType = "application/msexcel"
response.AddHeader "content-disposition","attachment; filename=aaa.xls"%>header("Content-type: application/msexcel");
header("Content-Disposition: attachment; filename=aaa.xls");?>filename=aaa.xls这个是默认下载的文件名;
application/unknown这个是指定当前页面生成的文件类型,这可以对应着windows里的MIME类型名称;
如是指定是word文档,你可以设置“application/msword”,指定是excel文档,你可设置“application/msexcel”。