Java ApachePOI到excel

Java ApachePOI到excel,java,excel,apache-poi,Java,Excel,Apache Poi,我正在使用Apache poi将值导出到excel。在达到32767行后,这些值将停止打印。 我已经实现了在另一张表中打印值的逻辑,它可以工作,但值会重复。。。。 有什么解决办法吗 protected void populateRows(History history, String mmddyy, HSSFSheet ss) { log.debug("populateRows(History, String, HSSFSheet)"); Array

我正在使用Apache poi将值导出到excel。在达到32767行后,这些值将停止打印。 我已经实现了在另一张表中打印值的逻辑,它可以工作,但值会重复。。。。 有什么解决办法吗

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);          
        }
    }
protectedvoid populateRows(历史记录,字符串mmddyy,HSSFSheet ss)
{
调试(“populateRows(历史记录、字符串、HSSFSheet)”;
ArrayList list=history.entryList;
Iterator it=list.Iterator();
while(it.hasNext())
{
单位u=(单位)it.next();
HSSFRow row=ss.createRow((短)ss.getLastRowNum()+1);
//HSSFRow row=ss.createRow(ss.getLastRowNum()+1);//由magesh添加
//System.out.println(“行数”+ss.getLastRowNum());
行=ExcelHelper.fillTheRowOnly(wb、行、numColumns);
SimpleDataFormat格式化程序=新的SimpleDataFormat(“MM/dd/yyyy”);
如果(u.id!=0)
{
row.getCell((短)COLNUM_ID).setCellValue(u.ID);
}
row.getCell((短)COLNUM_LENAME).setCellValue(history.LENAME);
row.getCell((短)COLNUM_CORPTAXCODE).setCellValue(history.CORPTAXCODE);
row.getCell((短)COLNUM_调整)。setCellValue(u调整);
row.getCell((短)COLNUM_ADJUSTED).setCellStyle(setPosFormat());
row.getCell((短)COLNUM_CARRYFORWARD).setCellValue(u.CARRYFORWARD);
row.getCell((短)COLNUM_CARRYFORWARD).setCellStyle(setPosFormat());
row.getCell((短)COLNUM_CUM_CARRYFORWARD).setCellValue(u.cumulativeCarryForward);
row.getCell((短)COLNUM_CUM_CARRYFORWARD).setCellStyle(setPosFormat());
row.getCell((短)COLNUM\u EXPIRED\u SYSTEM).setCellValue(u.expiredSystemGenerated);
row.getCell((短)COLNUM_EXPIRED_SYSTEM).setCellStyle(setPosFormat());
row.getCell((短)COLNUM_生成)。setCellValue(u生成);
row.getCell((短)COLNUM_生成).setCellStyle(setPosFormat());
row.getCell((短)COLNUM\u usabled\u SYSTEM).setCellValue(u.usabledSystemGenerated);
row.getCell((短)COLNUM__系统).setCellStyle(setPosFormat());
row.getCell((短)COLNUM_used).setCellValue(u.used);
getCell((短)COLNUM_used).setCellStyle(setPosFormat());
row.getCell((短)COLNUM_辖区).setCellValue(history.justictionName);
如果(history.year!=null)
{
row.getCell((短)COLNUM_NOLYEAR).setCellValue(formatter.format(history.year));
}
row.getCell((短)COLNUM_NOTES).setCellValue(u.NOTES);
if(u.unitType.equals(StateTaxConstants.NOL_调整))
{
row.getCell((短)COLNUM\u ADJUSTMENT\u DESCR).setCellValue(u adjustd\u DESCR);
}
如果(u.postDate!=null)
{
row.getCell((短)COLNUM_POSTDATE).setCellValue(formatter.format(u.POSTDATE));
}
如果(u.referenceDate!=null)
{
row.getCell((短)COLNUM_REFDATE).setCellValue(formatter.format(u.referenceDate));
}
row.getCell((短)COLNUM_USERNAME).setCellValue(u.USERNAME);
row.getCell((短)COLNUM_FEIN).setCellValue(history.FEIN);
row.getCell((短)COLNUM_revieved.setCellValue(u.revieved);
row.getCell((短)COLNUM_PREPOST).setCellValue(u.PREPOST);
row.getCell((短)COLNUM_HISTNAME).setCellValue(u.HISTNAME);
row.getCell((短)COLNUM_YRENDORIG).setCellValue(u.YRENDORIG);
}
}
受保护的void populateRows(历史记录、字符串mmddyy、HSSFSheet ss)
{
调试(“populateRows(历史记录、字符串、HSSFSheet)”;
ArrayList list=history.entryList;
Iterator it=list.Iterator();
while(it.hasNext())
{
单位u=(单位)it.next();
HSSFRow row=ss.createRow((短)ss.getLastRowNum()+1);
//HSSFRow row=ss.createRow(ss.getLastRowNum()+1);
//System.out.println(“行数”+ss.getLastRowNum());
行=ExcelHelper.fillTheRowOnly(wb、行、numColumns);
SimpleDataFormat格式化程序=新的SimpleDataFormat(“MM/dd/yyyy”);
如果(u.id!=0)
{
row.getCell((短)COLNUM_ID).setCellValue(u.ID);
}
row.getCell((短)COLNUM_LENAME).setCellValue(history.LENAME);
row.getCell((短)COLNUM_CORPTAXCODE).setCellValue(history.CORPTAXCODE);
}
}

问题出在您的代码中:

HSSFRow row = ss.createRow((short) ss.getLastRowNum() + 1);
您正在将行索引转换为短索引

请尝试以下代码:

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

问题出在您的代码中:

HSSFRow row = ss.createRow((short) ss.getLastRowNum() + 1);
您正在将行索引转换为短索引

请尝试以下代码:

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

我认为
HSSF
prfixed对象是旧的“xsl”样式,不能有更多的32767行。尝试新xlsx样式的
XSSF
前缀对象我认为
HSSF
prfixed对象是旧的“xsl”样式,不能有更多的32767行。对于新的xlsx样式,请尝试使用
XSSF
前缀对象