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;//設(shè)置合計(jì)所在的row
              label = new Label(0, 2, "統(tǒng)計(jì)日期:" + 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;//記得記錄的行數(shù)
               }

              }
             /* pointX = pointX+5;//加上投頭的5行
              label = new Label(0, pointX, "合計(jì)");//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文件進(jìn)行輸出
             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 閱讀(511) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2007年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(1)

          隨筆檔案(35)

          文章分類(5)

          文章檔案(2)

          新聞檔案(5)

          java link

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 乌海市| 阳新县| 罗源县| 沅陵县| 林口县| 芦山县| 永福县| 蒲城县| 枞阳县| 武城县| 安岳县| 若羌县| 凤台县| 海宁市| 枞阳县| 达拉特旗| 邓州市| 武冈市| 汝阳县| 廊坊市| 开鲁县| 阳东县| 仪征市| 临西县| 昌乐县| 琼中| 宁都县| 拉孜县| 宁国市| 鄯善县| 甘泉县| 太原市| 厦门市| 新宁县| 板桥市| 阜康市| 海林市| 泊头市| 合肥市| 集贤县| 天镇县|