资源推荐
资源详情
资源评论
response.setContentType("application/msexcel");
response.setHeader("Content-disposition","attachment; filename=filename.xls");
File newfile=new File(newfilepath);
if(!newfile.isFile()||!newfile.exists()){
throw new Exception("下载的文件路径或文件不存在!");
}
if(!newfile.getName().matches(".*\\.(?i)(xls)$")){
throw new Exception("只能导出'.xls'格式的文件");
}
FileInputStream fis = new FileInputStream(newfile);
BufferedInputStream buff = new BufferedInputStream(fis);
byte b[]= new byte[1024];
long k=0;
ServletOutputStream myout = response.getOutputStream();
while(k<newfile.length()){
int j = buff.read(b,0,1024);
k+=j;
myout.write(b,0,j);
}
myout.flush();
myout.close();
注意:若保存对话框不谈出,则可能是因为采用了java+ajax或java+extjs的同步传传输方式
如果是用的extjs可以这样写:
{
xtype:'button',
text:'导出excel',
iconCls:'iconcss_excel',
handler:function(){
var form=$("<form>");//定义一个form表单
form.attr("style","display:none");
response.setHeader("Content-disposition","attachment; filename=filename.xls");
File newfile=new File(newfilepath);
if(!newfile.isFile()||!newfile.exists()){
throw new Exception("下载的文件路径或文件不存在!");
}
if(!newfile.getName().matches(".*\\.(?i)(xls)$")){
throw new Exception("只能导出'.xls'格式的文件");
}
FileInputStream fis = new FileInputStream(newfile);
BufferedInputStream buff = new BufferedInputStream(fis);
byte b[]= new byte[1024];
long k=0;
ServletOutputStream myout = response.getOutputStream();
while(k<newfile.length()){
int j = buff.read(b,0,1024);
k+=j;
myout.write(b,0,j);
}
myout.flush();
myout.close();
注意:若保存对话框不谈出,则可能是因为采用了java+ajax或java+extjs的同步传传输方式
如果是用的extjs可以这样写:
{
xtype:'button',
text:'导出excel',
iconCls:'iconcss_excel',
handler:function(){
var form=$("<form>");//定义一个form表单
form.attr("style","display:none");










yhq470520016
- 粉丝: 0
- 资源: 2

上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
已下载
下载帮助

看过该资源的人还看了
没有合适的资源?快使用搜索试试~ 我知道了~
安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
前往页