设为首页 加入收藏

TOP

jxl创建excel并下载
2019-05-13 12:21:59 】 浏览:387
Tags:jxl 创建 excel 下载
版权声明:本文为博主原创文章,未经博主允许不得转载。(转载请注明出处) https://blog.csdn.net/u010416069/article/details/51197792

public void SaveExcel(HttpServletRequest request,HttpServletResponse response,StatisticsInfo statisticsInfo){
response.setContentType("application/vnd.ms-excel");
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhh24mmss");
String dateStr = simpleDateFormat.format(date);
response.setHeader("Content-Disposition", "attachment; filename=VehExcel"+dateStr+".xls ");
List<StatisticsInfo> list = null;
UserSession userSession = null;
OutputStream out = null;
try {
out = response.getOutputStream();
userSession = (UserSession)request.getSession().getAttribute("userSession");
//这回我自己的方法
list = (List<StatisticsInfo>) this.bztjServices.selectDrvFileTotal(statisticsInfo);
//创建工作薄
WritableWorkbook workbook = Workbook.createWorkbook(out);
//创建表格
WritableSheet writableSheet = workbook.createSheet("机动车档案数量统计", 0);
//列 行 名称
Label label=new Label(0,0,"序号");
Label label1=new Label(1,0,"管理部门");
Label label2=new Label(2,0,"录入人");
Label label3=new Label(3,0,"录入数量");
//添加单元格
writableSheet.addCell(label);
writableSheet.addCell(label1);
writableSheet.addCell(label2);
writableSheet.addCell(label3);
int count = 0;
for (int i = 0; i < list.size(); i++) {
//列 行 名称
Label labela=new Label(0,i+1,(i+1)+"");
Label labelb=new Label(1,i+1,list.get(i).getDaglbm());
Label labelc=new Label(2,i+1,list.get(i).getXm());
Label labeld=new Label(3,i+1,list.get(i).getTotal());
//添加单元格
writableSheet.addCell(labela);
writableSheet.addCell(labelb);
writableSheet.addCell(labelc);
writableSheet.addCell(labeld);
count = count + Integer.valueOf(list.get(i).getTotal());
}
//列 行 名称
Label labeltotal1=new Label(0,list.size()+2,"统计总数");
Label labeltotal2=new Label(1,list.size()+2,""+count);
//添加单元格
writableSheet.addCell(labeltotal1);
writableSheet.addCell(labeltotal2);
workbook.write();
workbook.close();
//out.write(b);
out.close();
//response.resetBuffer();
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}finally{
if(null != out){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
}
} 

页面直接掉方法就会有弹出来
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇sqoop   把 hdfs 和关系型数.. 下一篇正则符号解释

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目