我尝试遵循此处的解决方案: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);
因为您希望它的宽度为两列。
关于java - 生成行下双列的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33448528/