【发布时间】:2017-05-27 05:57:32
【问题描述】:
下面这段代码不起作用。
Table table = new Table(2);
table.setBorder(Border.NO_BORDER);
我是 iText 7 的新手,我只想让我的表格无边框。 比如怎么做?
【问题讨论】:
下面这段代码不起作用。
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);
【讨论】:
String 添加到Cell,只能添加IBlockElement 或Image。
您可以编写一个方法,通过 Table 的所有子项运行并设置 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);
而不是在所有单元格手册上更改它。
【讨论】: