生成 table 行下有双列
Generate table with double column beneath a row
我想创建一个 table 这样的 itext:
我尝试按照此处的解决方案:Create a table in a generated PDF 但不幸的是,M
和 F
列不会位于 Gender
列下方。据说它应该像答案中那样工作,但它不起作用。我不确定哪里出了问题。这是我的代码:
document.open();
PdfPTable table = new PdfPTable(5);
table.setWidths(new float[]{ 1f, 3f, 1f, 1f, 1f});
PdfPCell cell;
cell = new PdfPCell(new Phrase("Chapter"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Description"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(1);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Total"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("M");
table.addCell("F");
document.add(table);
document.close();
这是我当前的输出:
有人可以帮我解决这个问题吗??提前致谢。
我理解应该是:
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(2);
table.addCell(cell);
因为您希望它有两列宽。
我想创建一个 table 这样的 itext:
我尝试按照此处的解决方案:Create a table in a generated PDF 但不幸的是,M
和 F
列不会位于 Gender
列下方。据说它应该像答案中那样工作,但它不起作用。我不确定哪里出了问题。这是我的代码:
document.open();
PdfPTable table = new PdfPTable(5);
table.setWidths(new float[]{ 1f, 3f, 1f, 1f, 1f});
PdfPCell cell;
cell = new PdfPCell(new Phrase("Chapter"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Description"));
cell.setRowspan(2);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(1);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Total"));
cell.setRowspan(2);
table.addCell(cell);
table.addCell("M");
table.addCell("F");
document.add(table);
document.close();
这是我当前的输出:
有人可以帮我解决这个问题吗??提前致谢。
我理解应该是:
cell = new PdfPCell(new Phrase("Gender"));
cell.setColspan(2);
table.addCell(cell);
因为您希望它有两列宽。