I'll be back!

            Focus on BPM, celebrate PegaRULES Process Commander (PRPC)
          posts - 76, comments - 161, trackbacks - 0, articles - 2
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Pega引入Apache POI讀Excel

          Posted on 2012-09-12 22:43 zolly 閱讀(806) 評論(0)  編輯  收藏
          read xls - before Excel 2007
          try {
              PRFile file =new PRFile("Excel File Name.xls");

              java.io.BufferedInputStream in = new java.io.BufferedInputStream(
                      new PRInputStream(file));

              // open HSSFWorkbook
              org.apache.poi.poifs.filesystem.POIFSFileSystem fs = new org.apache.poi.poifs.filesystem.POIFSFileSystem(
                      in);
              org.apache.poi.hssf.usermodel.HSSFWorkbook wb = new org.apache.poi.hssf.usermodel.HSSFWorkbook(
                      fs);
              org.apache.poi.hssf.usermodel.HSSFCell cell = null;
              for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
                  org.apache.poi.hssf.usermodel.HSSFSheet st = wb
                          .getSheetAt(sheetIndex);
                  for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) {
                      org.apache.poi.hssf.usermodel.HSSFRow row = st
                              .getRow(rowIndex);
                      if (row == null) {
                          continue;
                      }

                      String strJobName = "";
                      cell = row.getCell(0);
                      strJobName = cell.getStringCellValue().trim();
                      ClipboardProperty propJobName = myStepPage.getProperty(".Jobs(<append>).JobName");
                      propJobName.setValue(strJobName);
                  }
              }
              in.close();
          catch (java.io.FileNotFoundException e) {
              oLog.error(e.getMessage());
          catch (java.io.IOException e) {
              oLog.error(e.getMessage());
          }

          Excel 2007 or later
          try {
              PRFile file =new PRFile("Excel File Name.xlsx");

              java.io.BufferedInputStream in = new java.io.BufferedInputStream(
                      new PRInputStream(file));
              // open XSSFWorkbook
              org.apache.poi.openxml4j.opc.OPCPackage docPackage = org.apache.poi.openxml4j.opc.OPCPackage
                      .open(in);

              org.apache.poi.xssf.usermodel.XSSFWorkbook wb = new org.apache.poi.xssf.usermodel.XSSFWorkbook(
                      docPackage);
              org.apache.poi.xssf.usermodel.XSSFCell cell = null;
              for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
                  org.apache.poi.xssf.usermodel.XSSFSheet st = wb
                          .getSheetAt(sheetIndex);
                  for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) {
                      org.apache.poi.xssf.usermodel.XSSFRow row = st
                              .getRow(rowIndex);
                      if (row == null) {
                          continue;
                      }

                      String strJobName = "";
                      cell = row.getCell(0);
                      strJobName = cell.getStringCellValue().trim();
                      ClipboardProperty propJobName = myStepPage.getProperty(".Jobs(<append>).JobName");
                      propJobName.setValue(strJobName);
                  }
              }
              in.close();
          catch (java.io.FileNotFoundException e) {
              oLog.error(e.getMessage());
          catch (java.io.IOException e) {
              oLog.error(e.getMessage());
          catch (org.apache.poi.openxml4j.exceptions.InvalidFormatException e) {
              oLog.error(e.getMessage());
          }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 镇江市| 嵩明县| 喀什市| 江津市| 平顺县| 郁南县| 永昌县| 台安县| 友谊县| 襄垣县| 柳河县| 海阳市| 常山县| 海城市| 兰州市| 宜宾县| 宁波市| 高雄县| 康定县| 东乌珠穆沁旗| 抚松县| 宣威市| 永泰县| 赫章县| 虹口区| 什邡市| 漠河县| 祁阳县| 台北县| 河间市| 浦东新区| 无棣县| 武宣县| 揭阳市| 承德县| 双江| 海淀区| 安新县| 保定市| 类乌齐县| 德江县|