`
fendou-cheng
  • 浏览: 12187 次
  • 性别: Icon_minigender_1
  • 来自: 河北石家庄
社区版块
存档分类
最新评论

jxl 导出excle

    博客分类:
  • jxl
阅读更多

WritableWorkbook book = Workbook.createWorkbook(response
    .getOutputStream());
  WritableSheet sheet = book.createSheet("交办卡片", 0);
  try {
   WritableFont rFont = new WritableFont(WritableFont.ARIAL, 14,
     WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
     Colour.BLACK);
   WritableCellFormat rCellFormat = new WritableCellFormat(rFont);
   rCellFormat.setAlignment(Alignment.CENTRE);
   rCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
   rCellFormat.setBorder(Border.ALL, BorderLineStyle.THIN);

   WritableFont conFont = new WritableFont(WritableFont.ARIAL, 12,
     WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
     Colour.BLACK);
   WritableCellFormat conCellFormat = new WritableCellFormat(conFont);
   conCellFormat.setAlignment(Alignment.CENTRE);
   conCellFormat.setBorder(Border.ALL, BorderLineStyle.THIN);

   Label wlabels = new Label(0, 0, "文号", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(1, 0, "来文机关", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(2, 0, "文件内容", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(3, 0, "交办时间", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(4, 0, "办结时间", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(5, 0, "主办处室", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(6, 0, "会办处室", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(7, 0, "办理情况", conCellFormat);
   sheet.addCell(wlabels);
   wlabels = new Label(8, 0, "领导批示", conCellFormat);
   sheet.addCell(wlabels);

   for (int i = 0; i < typeV.size(); ++i) {
    Map map = (HashMap) typeV.get(i);
    wlabels = new Label(0, 1 + i, (String) map.get("BH"),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(1, 1 + i, (String) map.get("JBK_LWJG"),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(2, 1 + i, (String) map.get("TITLE"),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(3, 1 + i, (String) map.get("JBK_JBRQ"),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(4, 1 + i, (String) map.get("JBK_BJRQ"),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(5, 1 + i, (String) map.get(""),
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(6, 1 + i, (String) map.get(""),
      conCellFormat);
    sheet.addCell(wlabels);

    wlabels = new Label(7, 1 + i, "end".equals(((String) map.get("CURNODE")))?"已办结":"未办结",         //判断是end的时候,为已办结。其余的为未办结
      conCellFormat);
    sheet.addCell(wlabels);
    wlabels = new Label(8, 1 + i, (String) map.get("JBK_LDPS"),
      conCellFormat);
    sheet.addCell(wlabels);
   }

   book.write();
   response.setContentType("aplication/msexcel");
   String fileName = "交办卡片";
   fileName = URLEncoder.encode(fileName, "utf-8");
   response.setHeader("Content-disposition", "attachment; filename="
     + fileName + ".xls");
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    book.close();
   } catch (WriteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
  return null;
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics