Java 如何从pdf输出中包含最后三(3)个table.addCell?

Java 如何从pdf输出中包含最后三(3)个table.addCell?,java,eclipse,pdf,itext,java-ee-7,Java,Eclipse,Pdf,Itext,Java Ee 7,我的代码无法读取最后3个table.addCell.(table.addCell(card.getPk().getCardNumber()); table.addCell(card.getStatus()); table.addCell(card.getAmount().toString());)我的代码中有什么错误 PdfPTable table = new PdfPTable(19); table.setWidthPercentage(100);

我的代码无法读取最后3个table.addCell.(table.addCell(card.getPk().getCardNumber()); table.addCell(card.getStatus()); table.addCell(card.getAmount().toString());)我的代码中有什么错误

        PdfPTable table = new PdfPTable(19);

        table.setWidthPercentage(100);

        PdfPCell column = new PdfPCell();

        column.setColspan(19);

        table.addCell(column);

        table.addCell(ReportConstants.REPORT_COLUMN_PURCHASE_DATE);
        table.addCell(ReportConstants.REPORT_COLUMN_PURCHASE_TIME);
        table.addCell(ReportConstants.REPORT_COLUMN_TRANSACTION_NUMBER);
        table.addCell(ReportConstants.REPORT_COLUMN_BUYERS_NAME);
        table.addCell(ReportConstants.REPORT_COLUMN_BUYERS_TYPE);
        table.addCell(ReportConstants.REPORT_COLUMN_CENTER);
        table.addCell(ReportConstants.REPORT_COLUMN_PAYMENT);
        table.addCell(ReportConstants.REPORT_COLUMN_IPG_REF);
        table.addCell(ReportConstants.REPORT_COLUMN_CREATED_BY);
        table.addCell(ReportConstants.REPORT_COLUMN_UPDATE_DT);
        table.addCell(ReportConstants.REPORT_COLUMN_UPDATE_BY);
        table.addCell(ReportConstants.REPORT_COLUMN_STATUS);
        table.addCell(ReportConstants.REPORT_COLUMN_CARD_TYPE);
        table.addCell(ReportConstants.REPORT_COLUMN_TTL_AMOUNT);
        table.addCell(ReportConstants.REPORT_COLUMN_OR_NUMBER);
        table.addCell(ReportConstants.REPORT_COLUMN_REMARKS);
        table.addCell(ReportConstants.REPORT_COLUMN_CARD_NUMBER);
        table.addCell(ReportConstants.REPORT_COLUMN_CARD_STATUS);
        table.addCell(ReportConstants.REPORT_COLUMN_AMOUNT);

    for(CardPurchaseReport cardPurchase : cardPurchases){

        table.addCell(dateFormat.format(cardPurchase.getPurchaseDate()));
        table.addCell(timeFormat.format(cardPurchase.getPurchaseDate()));
        table.addCell(cardPurchase.getPurchaseNumber());
        table.addCell(cardPurchase.getBuyerName());
        table.addCell(cardPurchase.getBuyerType());
        table.addCell(cardPurchase.getCenter());
        table.addCell(cardPurchase.getPaymentType());
        table.addCell(cardPurchase.getIpgRefNumber());
        table.addCell(cardPurchase.getCreatedBy());
        table.addCell(dateFormat.format(cardPurchase.getUpdatedDate()));
        table.addCell(cardPurchase.getUpdatedBy());
        table.addCell(cardPurchase.getStatus());
        table.addCell(cardPurchase.getCardType());
        table.addCell(cardPurchase.getTotalAmount().toString());
        table.addCell(cardPurchase.getOrNumber());
        table.addCell(cardPurchase.getRemarks());
        if(cardNums != null){
            for(CardMasterWS cardNum : cardNums){
                if(cardNum.getOrderTicket().equalsIgnoreCase(cardPurchase.getPurchaseNumber())){
                    CardMaster card = cardMasterDao.getCardDetails(cardNum.getCardNumber());
        table.addCell(card.getPk().getCardNumber());
        table.addCell(card.getStatus());
        table.addCell(card.getAmount().toString());
            }
        }
    }
}
    doc.add(table);
    doc.close();

嗨@mkl我发现有些唱片没有卡。我删除我的if(cardNum.getOrderTicket().equalsIgnoreCase(cardphase.getPurchaseNumber()))‌‌​​ 我更改代码如下:

        List<CardPurchaseDetail> cardsPurchased = cardPurchaseDetailDao.getPurchaseDetails(cardPurchase.getPurchaseNumber());
        if(cardsPurchased != null && cardsPurchased.size() > 0){
            int ctr = 0;
            for(CardPurchaseDetail cardPurchased : cardsPurchased){
                CardMaster card = cardMasterDao.getCardDetails(cardPurchased.getPk().getCardNumber());
                if(ctr > 0){
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                    table.addCell(" ");
                }
                table.addCell(bodyFontStyle (card.getPk().getCardNumber()));    
                table.addCell(bodyFontStyle (card.getStatus()));
                table.addCell(bodyFontStyle (card.getAmount().toString()));
                ctr++;
            }
        } else {
            table.addCell(" ");
            table.addCell(" ");
            table.addCell(" ");
        }
List cardsPurchased=cardPurchaseDetailDao.getPurchaseDetails(cardphase.getPurchaseNumber());
if(cardsPurchased!=null&&cardsPurchased.size()>0){
int ctr=0;
对于(卡购买详情卡购买:卡购买){
CardMaster card=cardMasterDao.getCardDetails(cardpowered.getPk().getCardNumber());
如果(ctr>0){
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
}
table.addCell(bodyFontStyle(card.getPk().getCardNumber());
table.addCell(bodyFontStyle(card.getStatus());
table.addCell(bodyFontStyle(card.getAmount().toString());
ctr++;
}
}否则{
表1.addCell(“”);
表1.addCell(“”);
表1.addCell(“”);
}

而且有效。:)

卡片的大小是多少?如果为零(0),则这三个
addCell
方法不运行是正常的。还要检查您的条件
if(cardNum.getOrderTicket().equalsIgnoreCase(cardphase.getPurchaseNumber())
如果返回
true
Hi@elefasGR谢谢。我的cardNums的大小是30,我的if语句为true.iText不会显示不完整的行。葬礼行有19个细胞吗?如果没有,请使用
setCompleteRows
完成最后一行。@BrunoLowagie最后一行有19个单元格。您是否确保
cardNum.getOrderTicket().equalsIgnoreCase(cardPurchase.getPurchaseNumber())
变为真?例如,使用日志语句?