java action jxl 生成并下载excel(二)

2014-11-24 09:07:01 · 作者: · 浏览: 5
.write(buffer, 0, len);
}
bos.close();
sos.close();
bis.close();

} catch (Exception e) {
log.error("获取打车请求量出错", e);
}

}
public String excelSave(List list,String excelName){

String path="D:\\UpLoadFile\\" + excelName + ".xls";
try{

WritableWorkbook book = Workbook.createWorkbook(new File(
path));

WritableSheet sheet = book.createSheet("sheet_1", 0);
jxl.write.WritableFont font1 = new jxl.write.WritableFont(
jxl.write.WritableFont.TIMES, 16,
jxl.write.WritableFont.BOLD);
jxl.write.WritableFont font3 = new jxl.write.WritableFont(
jxl.write.WritableFont.TIMES, 10,
jxl.write.WritableFont.BOLD);
jxl.write.WritableCellFormat CBwcfF1 = new jxl.write.WritableCellFormat(
font1);
jxl.write.WritableCellFormat CBwcfF2 = new jxl.write.WritableCellFormat();
jxl.write.WritableCellFormat CBwcfF3 = new jxl.write.WritableCellFormat(
font3);
jxl.write.WritableCellFormat CBwcfF4 = new jxl.write.WritableCellFormat();
CBwcfF1.setAlignment(jxl.write.Alignment.CENTRE);
CBwcfF2.setAlignment(jxl.write.Alignment.RIGHT);
CBwcfF3.setAlignment(jxl.write.Alignment.CENTRE);
CBwcfF3.setBorder(Border.ALL, jxl.format.BorderLineStyle.THIN,
Colour.BLACK);
CBwcfF4.setBorder(Border.ALL, jxl.format.BorderLineStyle.THIN,
Colour.BLACK);
Label labelhead16 = new Label(0, 0, "透明球统计信息表", CBwcfF1);

sheet.addCell(labelhead16);


sheet.mergeCells(0, 0, 12, 0);
sheet.mergeCells(0, 1, 12, 1);

sheet.setColumnView(0, 5);
sheet.setColumnView(1, 25);
sheet.setColumnView(2, 25);
Label labelhead0 = new Label(0, 2, " 序号", CBwcfF3);
Label labelhead1 = new Label(1, 2, " 日 期", CBwcfF3);
Label labelhead2 = new Label(2, 2, " 应召数量", CBwcfF3);
sheet.addCell(labelhead0);
sheet.addCell(labelhead1);
sheet.addCell(labelhead2);

for (int i = 0; i < list.size(); i++) {
ReportCallInfo data=list.get(i);

Label label0 = new Label(0, i + 3, i + 1 + "", CBwcfF4);
Label label1 = new Label(1, i + 3, formatString(data
.getNowday()), CBwcfF4);
Label label2 = new Label(2, i + 3, formatString(data
.getCallnum()), CBwcfF4);


sheet.addCell(label0);
sheet.addCell(label1);
sheet.addCell(label2);
}
log.debug("导出excel成功");


book.write();
book.close();

}catch (Exc