以下代码不起作用。
Table table = new Table(2);
table.setBorder(Border.NO_BORDER);
我刚接触iText 7,我想让我的表格没有边框,应该怎么做呢?
在iText7中,表格本身默认不负责边框,而是由单元格来控制。如果您想要一个无边框的表格,您需要将每个单元格都设置为无边框(或者在仍然希望有内部边框的情况下,将外部单元格设置为无边框)。
Cell cell = new Cell();
cell.add("contents go here");
cell.setBorder(Border.NO_BORDER);
table.addCell(cell);
你可以编写一个方法,遍历表格的所有子元素并设置 NO_BORDER。
private static void RemoveBorder(Table table)
{
for (IElement iElement : table.getChildren()) {
((Cell)iElement).setBorder(Border.NO_BORDER);
}
}
这样做有一个好处,您仍然可以使用
table.add("whatever");
table.add("whatever");
RemoveBorder(table);
而不是手动更改所有单元格。
table.GetChildren().OfType<Cell>()
。 - Metro Smurfprivate static void setInnerCellBorder(Table table, Border border) {
for (IElement child : table.getChildren()) {
if (child instanceof Cell) {
((Cell) child).setBorder(border);
}
}
}
setInnerCellBorder(table, Border.NO_BORDER);
// or if you want a different color size you can do
setInnerCellBorder(Table, new SolidBorder(ColorConstants.RED, 2));
String
添加到Cell
中,只能添加IBlockElement
或者Image
。 - Evgenij Reznik