2014-09-04 153 views
0

我使用Apache poi將值導出到excel.after達到32767行後,值停止打印。 我已經實現了打印其他表中的值的邏輯,它的工作原理,但價值重複.... 任何解決方案??????Apache poi excel

protected void populateRows(History history, String mmddyy, HSSFSheet ss) 
    { 
     log.debug("populateRows(History, String, HSSFSheet)"); 

     ArrayList<Unit> list = history.entryList; 

     Iterator it = list.iterator(); 

     while (it.hasNext()) 
     { 
      Unit u = (Unit) it.next(); 
      HSSFRow row = ss.createRow((short) ss.getLastRowNum() + 1); 

//   HSSFRow row = ss.createRow(ss.getLastRowNum() + 1);//added by magesh 

//   System.out.println("number of rows "+ ss.getLastRowNum()); 
      row = ExcelHelper.fillTheRowOnly(wb, row, numColumns); 
      SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 

      if (u.id != 0) 
      { 
       row.getCell((short) COLNUM_ID).setCellValue(u.id); 
      } 

      row.getCell((short) COLNUM_LENAME).setCellValue(history.lename); 
      row.getCell((short) COLNUM_CORPTAXCODE).setCellValue(history.corptaxcode); 

      row.getCell((short) COLNUM_ADJUSTED).setCellValue(u.adjusted); 
      row.getCell((short) COLNUM_ADJUSTED).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_CARRYFORWARD).setCellValue(u.carryForward); 
      row.getCell((short) COLNUM_CARRYFORWARD).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_CUM_CARRYFORWARD).setCellValue(u.cumulativeCarryForward); 
      row.getCell((short) COLNUM_CUM_CARRYFORWARD).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_EXPIRED_SYSTEM).setCellValue(u.expiredSystemGenerated); 
      row.getCell((short) COLNUM_EXPIRED_SYSTEM).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_GENERATED).setCellValue(u.generated); 
      row.getCell((short) COLNUM_GENERATED).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_UTILIZED_SYSTEM).setCellValue(u.utilizedSystemGenerated); 
      row.getCell((short) COLNUM_UTILIZED_SYSTEM).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_UTILIZED).setCellValue(u.utilized); 
      row.getCell((short) COLNUM_UTILIZED).setCellStyle(setPosFormat()); 

      row.getCell((short) COLNUM_JURISDICTION).setCellValue(history.jurisdictionName); 

      if (history.year != null) 
      { 
       row.getCell((short) COLNUM_NOLYEAR).setCellValue(formatter.format(history.year)); 
      } 

      row.getCell((short) COLNUM_NOTES).setCellValue(u.notes); 

      if (u.unitType.equals(StateTaxConstants.NOL_ADJUSTMENT)) 
      { 
       row.getCell((short) COLNUM_ADJUSTMENT_DESCR).setCellValue(u.adjusted_descr); 
      } 

      if(u.postDate != null) 
      { 
       row.getCell((short) COLNUM_POSTDATE).setCellValue(formatter.format(u.postDate)); 
      } 

      if (u.referenceDate != null) 
      { 
       row.getCell((short) COLNUM_REFDATE).setCellValue(formatter.format(u.referenceDate)); 
      } 

      row.getCell((short) COLNUM_USERNAME).setCellValue(u.userName); 
      row.getCell((short) COLNUM_FEIN).setCellValue(history.fein); 
      row.getCell((short) COLNUM_REVIEWED).setCellValue(u.reviewed); 
      row.getCell((short) COLNUM_PREPOST).setCellValue(u.prepost); 
      row.getCell((short) COLNUM_HISTNAME).setCellValue(u.histname); 
      row.getCell((short) COLNUM_YRENDORIG).setCellValue(u.yrendorig); 

     } 
    } 
protected void populateRows(History history, String mmddyy, HSSFSheet ss) 
    { 
     log.debug("populateRows(History, String, HSSFSheet)"); 

     ArrayList<Unit> list = history.entryList; 

     Iterator it = list.iterator(); 

     while (it.hasNext()) 
     { 
      Unit u = (Unit) it.next(); 
      HSSFRow row = ss.createRow((short) ss.getLastRowNum() + 1); 

//   HSSFRow row = ss.createRow(ss.getLastRowNum() + 1);   
//   System.out.println("number of rows "+ ss.getLastRowNum()); 
      row = ExcelHelper.fillTheRowOnly(wb, row, numColumns); 
      SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 

      if (u.id != 0) 
      { 
       row.getCell((short) COLNUM_ID).setCellValue(u.id); 
      } 

      row.getCell((short) COLNUM_LENAME).setCellValue(history.lename); 
      row.getCell((short) COLNUM_CORPTAXCODE).setCellValue(history.corptaxcode);   
     } 
    } 
+0

我想'HSSF' prfixed對象是不能有更多的32767行老「XSL」風格。爲新的xlsx樣式嘗試'XSSF'前綴對象 – Jens 2014-09-04 10:16:34

+0

以下是[Excel](http://superuser.com/a/366473/230998)的行限制 – 2014-09-04 15:09:04

回答

6

的問題是在你的代碼:

HSSFRow row = ss.createRow((short) ss.getLastRowNum() + 1); 

你鑄行索引短。

試試這個代碼,而不是:

HSSFRow row = ss.createRow((int) ss.getLastRowNum() + 1);