java导出excel表格_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java导出excel表格

java导出excel表格

 2014/12/18 15:32:30  shiqiaopinglove  程序员俱乐部  我要评论(0)
  • 摘要:List<PhoneLogDto>list=newArrayList<T>();//换成数据源response.setContentType("application/msexcel");response.setHeader("Content-disposition","attachment;filename=name.xls");//设定输出文件名称OutputStreamos=response.getOutputStream()
  • 标签:excel 导出excel Java 表格

??????? List<PhoneLogDto> list=new ArrayList<T>(); //换成数据源
??? ??? response.setContentType("application/msexcel");
??? ??? response.setHeader("Content-disposition", "attachment; filename=name.xls");// 设定输出文件名
??? ??? OutputStream os = response.getOutputStream();
??? ??? WritableWorkbook wwb = Workbook.createWorkbook(os);//创建可写工作薄??
??? ??? WritableSheet ws = wwb.createSheet("sheet1", 0);//创建可写工作表
??? ??? ws.addCell(new Label(0,0,"列名1"));//列数随你控制
??? ??? ws.addCell(new Label(1,0,"列名2"));
??? ??? ws.addCell(new Label(2,0,"列名3"));
??? ??? ws.addCell(new Label(3,0,"列名4"));
??? ??? ws.addCell(new Label(4,0,"列名5"));
??? ??? ws.addCell(new Label(5,0,"列名6"));
??? ??? ws.addCell(new Label(6,0,"列名7"));
??? ??? int i=1;
??? ??? for(T obj:list){
??? ??? ??? ws.addCell(new Label(0,i,obj.getName()));//此处obj是个对象
??? ??? ??? ws.addCell(new Label(1,i,obj.getName()));
??? ??? ??? ws.addCell(new Label(2,i,obj.getName()));
??? ??? ??? ws.addCell(new Label(3,i,obj.getName()));
??? ??? ??? ws.addCell(new Label(4,i,obj.getName()));
??? ??? ??? ws.addCell(new Label(5,i,obj.getName()));
??? ??? ??? ws.addCell(new Label(6,i,obj.getName()));
??? ??? ??? i++;
??? ??? }
??? ??? //现在可以写了??
??? ??? wwb.write();
??? ??? //写完后关闭??
??? ??? wwb.close();
??? ??? //输出流也关闭吧??
??? ??? os.close();

发表评论
用户名: 匿名