WritableSheet ws=null;
OutputStream os = response.getOutputStream();
wwb = Workbook.createWorkbook(os);
ws=wwb.createSheet("员工编号",0);
ws.getSettings().setDefaultColumnWidth(15);
ws.setColumnView(0,20);
ws.setColumnView(1,20);
ws.setColumnView(2,80);
Label label = new Label(0,0,"日期"); // 列 行 名称
ws.addCell(label);
label = new Label(1,0,"薪资");
ws.addCell(label);
label = new Label(2,0,"增幅");
ws.addCell(label);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment; filename="+new String((titlename).getBytes("gbk"),"iso8859-1")+".xls");
if(null!=pro_List && pro_List.size()>0){
Map oneMap = null ;
for(int i=0;i<pro_List.size();i++){
oneMap = pro_List.get(i) ;
label = new Label(0,(i+1),CommonString.getFormatPara(oneMap.get("date"))) ;
ws.addCell(label);
label = new Label(1,(i+1),CommonString.getFormatPara(oneMap.get("money"))) ;
ws.addCell(label);
label = new Label(2,(i+1),CommonString.getFormatPara(oneMap.get("amplification")).equals("")?"0":CommonString.getFormatPara(oneMap.get("amplification"))+"%") ;
ws.addCell(label);
}
}
wwb.write();
wwb.close();
os.close();
os = null ;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
本文介绍了一种利用Java JXL库创建Excel文件的方法。通过示例代码详细展示了如何设置工作簿、工作表,以及如何定义单元格内容和格式。此外,还介绍了如何将Java集合中的数据写入到Excel中,并设置了响应头实现文件下载。
293

被折叠的 条评论
为什么被折叠?



