* 导出Excel报表
* @param req
* @param rep
* @return
* @throws IOException
*/
Public Map List rep.reset(); //写入流 OutputStream os = rep.getOutputStream(); //创建工作表 WritableWorkbook wwb = Workbook.createWorkbook(os); try { list = testDCJService.getAll(null); //创建时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //文件格式 String fileName = "info_"+sdf.format(new Date())+".xls"; // rep.setContentType("application/x-msdownload"); // rep.setHeader("Content-disposition","attachment;filename="+new String(fileName.getBytes(),"iso-8859-1")); //从集合中获取他的长度 int ncount = list.size(); // 一次最多写入量 int maxNum = 50000; int times = (ncount + maxNum ) / maxNum; //打印 System.out.println(times); for(int i = 0; i < times; i++){ // 新建一张表 WritableSheet wsheet = wwb.createSheet("members_" + (i+1),i); // 设置表头 Label label = new Label(0,0,""); try { wsheet.addCell(label); label = new Label(0,0,"用户编号"); wsheet.addCell(label); label = new Label(1,0,"用户名称"); wsheet.addCell(label); label = new Label(2,0,"用户年龄"); wsheet.addCell(label); // 读出数据 int base = (times-1==i)?ncount%50000:50000; for(int j = 0; j < base; j++){ TestDCJ testDcj = list.get(j); label = new Label(0,(j+1),String.valueOf(testDcj.getId())); wsheet.addCell(label); label = new Label(1,(j+1),testDcj.getUserName()); wsheet.addCell(label); label = new Label(2,(j+1),String.valueOf(testDcj.getUserAge())); wsheet.addCell(label); } } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); }finally{ //执行写入操作 wwb.write(); //关闭操作 wwb.close(); os.close(); } } } catch (IOException e) { e.printStackTrace(); } return null; }