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");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值