【问题标题】:How can I include the last three (3) table.addCell from the output of my pdf?如何从我的 pdf 输出中包含最后三 (3) 个 table.addCell?
【发布时间】:2016-02-22 08:31:24
【问题描述】:

我的代码无法读取最后 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();

【问题讨论】:

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

标签: java eclipse pdf itext java-ee-7


【解决方案1】:

嗨@mkl,我发现有些记录没有卡片。我删除了我的 if(cardNum.getOrderTicket().equalsIgnoreCase(cardPurchase.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(" ");
        }

而且它有效。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多