posts - 35,  comments - 6,  trackbacks - 0

StorehousePrintBPO bpo = new StorehousePrintBPO();
   List objectList = bpo.getPrintRs(startDate, endDate);
   Workbook rwb = null;
   WritableWorkbook wwb = null;
   File outputFile = null;
   Label label = null;
   try {
    String path = this.servlet.getServletContext().getRealPath("/");
    rwb = Workbook.getWorkbook(new File(path
      + "reports/excel/storehouse.xls"));
    outputFile = new File(path
      + "reports/excel/temp_storehouse.xls");
    wwb = Workbook.createWorkbook(outputFile, rwb);
    WritableSheet sheet = wwb.getSheet(0);
    WritableCellFormat wcf = new WritableCellFormat();
    wcf.setBorder(jxl.format.Border.ALL,
      jxl.format.BorderLineStyle.THIN);
    wcf.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
    wcf.setAlignment(jxl.format.Alignment.CENTRE);
    wcf.setWrap(true);
    //int pointX=0;//设置合计所在的row
    label = new Label(0, 2, "统计日期:" + startDate + "--" + endDate);
    sheet.addCell(label);
    if (objectList.size() > 0) {
     for (int i = 0; i < objectList.size(); i++) {
      // sheet = wwb.getSheet(i + 3);
      List listrow = (List) objectList.get(i);
      for (int j = 0; j < listrow.size(); j++) {
       // WritableCell cell = sheet.getWritableCell(i+3,
       // j);
       String value = (String) listrow.get(j);
       /*
        * if (cell.getType() == CellType.LABEL) { Label l =
        * (Label) cell; l.setString(value); }
        */
       label = new Label(j, i + 5, value, wcf);
       sheet.addCell(label);

      }
      //pointX = i;//记得记录的行数
     }

    }
   /* pointX = pointX+5;//加上投头的5行
    label = new Label(0, pointX, "合计");//new Label(列,行,值)
    sheet.addCell(label);
    for(int i=0;i<4;i++){
    label = new Label(i+1, pointX, "value");//new Label(列,行,值)
    sheet.addCell(label);
    }*/
    // sheet.addCell(label);
    wwb.write();
   } catch (Exception e) {
    e.printStackTrace();
   } finally {

    if (wwb != null) {
     wwb.close();
    }
    if (rwb != null) {
     rwb.close();
    }
   }

   // 以下部分将excel文件进行输出
   BufferedInputStream bis = null;
   BufferedOutputStream bos = null;
   ServletOutputStream outputStream = servletResponse
     .getOutputStream();
   servletResponse.reset();
   servletResponse
     .setContentType("application/vnd.ms-excel;charset=GBK");
   servletResponse.setHeader("Content-Disposition", "inline");
   URL url = outputFile.toURL();
   bis = new BufferedInputStream(url.openStream());
   bos = new BufferedOutputStream(outputStream);

   byte[] buff = new byte[2024];
   int bytesRead;

   while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
    bos.write(buff, 0, bytesRead);
   }
   if (bis != null) {
    bis.close();
   }
   if (bos != null) {
    bos.close();
   }
   if (outputFile.exists()) {
    outputFile.delete();
   }

   return null;

posted on 2007-04-18 09:25 NG 阅读(507) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问  
 
<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(1)

随笔档案(35)

文章分类(5)

文章档案(2)

新闻档案(5)

java link

搜索

  •  

最新评论

阅读排行榜

评论排行榜