首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

java导出步骤

2012-08-21 
java导出方法//导出方法 public void WriteToOutputStream(OutputStream out, String excelName,List list

java导出方法

//导出方法 public void WriteToOutputStream(OutputStream out, String excelName,List list) throws Exception {WritableWorkbook workbook = Workbook.createWorkbook(out);WritableSheet sheet = workbook.createSheet(excelName, 0);WritableCellFormat ccf = new WritableCellFormat();ccf.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);ccf.setAlignment(jxl.format.Alignment.CENTRE);WritableCellFormat numcf = new WritableCellFormat(new NumberFormat("#,##0.00"));numcf.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);numcf.setAlignment(jxl.format.Alignment.RIGHT);WritableCellFormat zbcf = new WritableCellFormat();zbcf.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);zbcf.setAlignment(jxl.format.Alignment.LEFT);//设置列头sheet.addCell(new Label(0, 0, "名称", zbcf));sheet.addCell(new Label(1, 0, "性别", zbcf));sheet.addCell(new Label(2, 0, "地址", zbcf));sheet.setColumnView(0, 16);    //循环输出值for (int i = 0; i < list.size(); i++) {Map map = (Map)list.get(i);String name =map.get("name").toString();sheet.addCell(new Label(0, i+1, String.valueOf(name), zbcf));String sex = map.get("sex").toString();sheet.addCell(new Label(1, i+1, String.valueOf(sex), zbcf));String add = map.get("add").toString();sheet.addCell(new Label(2, i+1, String.valueOf(add), zbcf));}workbook.write();workbook.close();}

//action 调用response.reset();response.setHeader("Content-Disposition", "attachment; filename=""+ new String("个人信息导出".getBytes("gb2312"),"iso8859-1") + ".xls"");export.WriteToOutputStream(response.getOutputStream(),"个人信息导出", list);response.setContentType("application/ms-excel;charset=gb2312");

热点排行