设为首页 加入收藏

TOP

jxl创建excel并下载
2019-05-13 12:21:59 】 浏览:41
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,"序号");
L
		    

abel 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 和关系型数.. 下一篇正则符号解释

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(217) }