概述
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");
最后
以上就是怕孤单书包为你收集整理的java前端建立过程步骤,java导出步骤的全部内容,希望文章能够帮你解决java前端建立过程步骤,java导出步骤所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复