Ext导出EXCEL,前后台代码

前台

new Ext.Button({
text:'导出EXCEL',
handler:function(){
var appWindow = window.open("getExecl.do"); //调action得到数据生成execl格式的数据,response发往前台
appWindow.focus();
}
})

后台: filename是导出的文件名,heads是excel表头,datalist是数据

public void createExcelStream(HttpServletResponse response,String filename,String[] heads,List<String[]> datalist){
try{
OutputStream os = response.getOutputStream();
WritableWorkbook wbook = Workbook.createWorkbook(os);
WritableSheet wsheet = wbook.createSheet(filename, 0);
for(int i=0 ; i<heads.length ; i++) {
Label label =new Label(i,0 ,heads[i]);
wsheet.addCell(label);
}
for(int i=0 ;i<datalist.size();i++) {
for(int j=0 ; j<datalist.get(i).length ; j++){
Label label =new Label(j,i+1 ,datalist.get(i)[j]);
wsheet.addCell(label);
}
}
response.setHeader("Content-disposition","attachment;" +
"filename="+ new String(filename.getBytes("GBK"), "ISO_8859_1") +".xls");
response.setContentType("application/vnd.ms-excel");
wbook.write();
wbook.close();
os.close();
}catch(Exception e){
e.printStackTrace();
}
} }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值