Table 在 IText 中未添加正确的单元格
Table In IText not adding correct Cells
我正在 Itext 中创建一个文档,并将其分解为 4 个主单元格,其中嵌套了表格。我正在创建文档的最后一个单元格,但只能显示每行中的第一个单元格。
这是我正在调用的函数,它返回一个我要添加到我的主文档中的单元格。
public PdfPCell getPSBioCell() {
PdfPCell spaceCell = new PdfPCell(new Phrase(""));
spaceCell.setColspan(1); // space
spaceCell.setBorder(0);
PdfPTable table = new PdfPTable(4);
PdfPCell main = new PdfPCell();
noBorder(main);//
main.setPadding(0);//
PdfPCell dist = new PdfPCell(new Phrase(_rangerDistrict, nf));
PdfPCell district = new PdfPCell(new Phrase(this.sale.getRangerDistrict(), nf));
PdfPCell saleD = new PdfPCell(new Phrase(_saleDate, nf));
PdfPCell saleDate = new PdfPCell(new Phrase(this.formatDateString(sale.getSaleDate()), nf));
PdfPCell awardD = new PdfPCell(new Phrase(_awardDate, nf));
PdfPCell awardDate = new PdfPCell(new Phrase(this.formatDateString(sale.getAwardDate()), nf));
PdfPCell termD = new PdfPCell(new Phrase(_termDate, nf));
PdfPCell termDate = new PdfPCell(new Phrase(this.formatDateString(sale.getTerminationDate()), nf));
PdfPCell avg = new PdfPCell(new Phrase(_avgDbh , nf));
PdfPCell avgDbh = new PdfPCell(new Phrase(this.formatNumberString(String.valueOf(sale.getAveDiam())), nf));
PdfPCell cruis = new PdfPCell(new Phrase(_cruiser, nf));
PdfPCell cruiser = new PdfPCell(new Phrase(sale.getCruiser(), nf));
noBorder(dist, district, saleD, saleDate);
noBorder(awardD, awardDate, termD, termDate, avg);
noBorder(avgDbh, cruis, cruiser);
//
table.addCell(dist);
table.addCell(district);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(saleD);
table.addCell(saleDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(awardD);
table.addCell(awardDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(termD);
table.addCell(termDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(avg);
table.addCell(avgDbh);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(cruis);
table.addCell(cruiser);
table.addCell(spaceCell);
table.addCell(spaceCell);
table.setWidthPercentage(100);
main.addElement(table);
return main;
}
这里的问题是在我的 noBorder(PdfPcell)
函数中,我正在做 cell.setBorder(0)
,但我也在做 cell.noWrap(true)
,所以将边框设置为 0
,将 noWrap 设置为 true
我看不到其他单元格被推离已完成的 Pdf 页面。
我正在 Itext 中创建一个文档,并将其分解为 4 个主单元格,其中嵌套了表格。我正在创建文档的最后一个单元格,但只能显示每行中的第一个单元格。
这是我正在调用的函数,它返回一个我要添加到我的主文档中的单元格。
public PdfPCell getPSBioCell() {
PdfPCell spaceCell = new PdfPCell(new Phrase(""));
spaceCell.setColspan(1); // space
spaceCell.setBorder(0);
PdfPTable table = new PdfPTable(4);
PdfPCell main = new PdfPCell();
noBorder(main);//
main.setPadding(0);//
PdfPCell dist = new PdfPCell(new Phrase(_rangerDistrict, nf));
PdfPCell district = new PdfPCell(new Phrase(this.sale.getRangerDistrict(), nf));
PdfPCell saleD = new PdfPCell(new Phrase(_saleDate, nf));
PdfPCell saleDate = new PdfPCell(new Phrase(this.formatDateString(sale.getSaleDate()), nf));
PdfPCell awardD = new PdfPCell(new Phrase(_awardDate, nf));
PdfPCell awardDate = new PdfPCell(new Phrase(this.formatDateString(sale.getAwardDate()), nf));
PdfPCell termD = new PdfPCell(new Phrase(_termDate, nf));
PdfPCell termDate = new PdfPCell(new Phrase(this.formatDateString(sale.getTerminationDate()), nf));
PdfPCell avg = new PdfPCell(new Phrase(_avgDbh , nf));
PdfPCell avgDbh = new PdfPCell(new Phrase(this.formatNumberString(String.valueOf(sale.getAveDiam())), nf));
PdfPCell cruis = new PdfPCell(new Phrase(_cruiser, nf));
PdfPCell cruiser = new PdfPCell(new Phrase(sale.getCruiser(), nf));
noBorder(dist, district, saleD, saleDate);
noBorder(awardD, awardDate, termD, termDate, avg);
noBorder(avgDbh, cruis, cruiser);
//
table.addCell(dist);
table.addCell(district);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(saleD);
table.addCell(saleDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(awardD);
table.addCell(awardDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(termD);
table.addCell(termDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(avg);
table.addCell(avgDbh);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(cruis);
table.addCell(cruiser);
table.addCell(spaceCell);
table.addCell(spaceCell);
table.setWidthPercentage(100);
main.addElement(table);
return main;
}
这里的问题是在我的 noBorder(PdfPcell)
函数中,我正在做 cell.setBorder(0)
,但我也在做 cell.noWrap(true)
,所以将边框设置为 0
,将 noWrap 设置为 true
我看不到其他单元格被推离已完成的 Pdf 页面。