欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

作导出excel文件操作

更新时间: 2014-01-05 02:56:39 责任编辑: Author_N1

 

做导出excel文件操作
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename=" + java.net.URLEncoder.encode("业绩目标列表.xls","UTF-8"));
WritableWorkbook book = Workbook.createWorkbook(response.getOutputStream());
// sheet
WritableSheet sheet = book.createSheet("业绩目标列表", 0);
// 内容项
// 行头label
        WritableFont titlefont = new WritableFont(WritableFont.createFont("宋体"), 14, WritableFont.BOLD);
        WritableFont labelfont = new WritableFont(WritableFont.createFont("宋体"), 12, WritableFont.BOLD);
        WritableFont textfont = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD);
       
        WritableCellFormat titleformat = new WritableCellFormat(titlefont);
        WritableCellFormat labelformat = new WritableCellFormat(labelfont);
        //文本格式
        WritableCellFormat textformat = new WritableCellFormat(NumberFormats.TEXT);
       
        labelformat.setAlignment(Alignment.CENTRE);
        labelformat.setVerticalAlignment(VerticalAlignment.CENTRE);
       
        textformat.setAlignment(Alignment.LEFT);
        textformat.setVerticalAlignment(VerticalAlignment.CENTRE);       
       
//        sheet.setRowView(0, 400);
       
        sheet.setColumnView(0, 20);
        sheet.setColumnView(1, 20);
        sheet.setColumnView(2, 20);
        sheet.setColumnView(3, 20);
        sheet.setColumnView(4, 20);
        sheet.setColumnView(5, 20);
        sheet.setColumnView(6, 20);
        sheet.setColumnView(7, 20);
        sheet.setColumnView(8, 30);
       
       
        Label label = new Label(0, 0, "组别名称",labelformat);
sheet.addCell(label);

label = new Label(1, 0, "月份",labelformat);
sheet.addCell(label);

label = new Label(2, 0, "目标1",labelformat);
sheet.addCell(label);

label = new Label(3, 0, "目标2",labelformat);
sheet.addCell(label);

label = new Label(4, 0, "目标3",labelformat);
sheet.addCell(label);

label = new Label(5, 0, "目标4",labelformat);
sheet.addCell(label);

label = new Label(6, 0, "目标5",labelformat);
sheet.addCell(label);
label = new Label(7, 0, "目标6",labelformat);
sheet.addCell(label);
label = new Label(8, 0, "每日平均通时目标业绩(分钟)",labelformat);
sheet.addCell(label);

if(teamDtoList!=null && teamDtoList.size()>0){
for(int i=0;i<teamDtoList.size();i++){

CustomerDTO niceDto1 = (CustomerDTO)teamDtoList.get(i);

label = new Label(0, i+1, niceDto1.getGroupname(),textformat);
sheet.addCell(label);

label = new Label(1, i+1, niceDto1.getInitMonth(),textformat);
sheet.addCell(label);


if(null==niceDto1.getEndNumberStr()||niceDto1.getEndNumberStr()==""){
label =new Label(2, i+1,"",textformat);
}else{
label =new Label(2, i+1, niceDto1.getEndNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getChallengeNumberStr()||niceDto1.getChallengeNumberStr()==""){
label = new Label(3, i+1,"",textformat);
}else{
label = new Label(3, i+1, niceDto1.getChallengeNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getThreeNumberStr()||niceDto1.getThreeNumberStr()==""){
label = new Label(4, i+1,"",textformat);
}else{
label = new Label(4, i+1, niceDto1.getThreeNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getFourNumberStr()||niceDto1.getFourNumberStr()==""){
label = new Label(5, i+1,"",textformat);
}else{
label = new Label(5, i+1, niceDto1.getFourNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getFiveNumberStr()||niceDto1.getFiveNumberStr()==""){
label = new Label(6, i+1, "",textformat);
}else{
label = new Label(6, i+1, niceDto1.getFiveNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getSixNumberStr()||niceDto1.getSixNumberStr()==""){
label = new Label(7, i+1, "",textformat);
}else{
label = new Label(7, i+1, niceDto1.getSixNumberStr(),textformat);
}
sheet.addCell(label);

if(null==niceDto1.getAveragePassTime()){
label = new Label(8, i+1,"",textformat);
}else{
label = new Label(8, i+1, niceDto1.getAveragePassTime().toString(),textformat);
}
sheet.addCell(label);
}
}

book.write();
book.close();
           
    return null;
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:56:39
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/16448/
本文WWW.DOC100.NET DOC100.NET版权所有。