简体   繁体   English

iText 7 无边框表格(无边框)

[英]iText 7 borderless table (no border)

This code below does not work.下面的这段代码不起作用。

Table table = new Table(2); 
table.setBorder(Border.NO_BORDER);

I am new to iText 7 and all I wanted is to have my table borderless.我是 iText 7 的新手,我想要的只是让我的表格无边框。 Like how to do it?喜欢怎么做?

The table itself is by default not responsible for borders in iText7, the cells are.默认情况下,表格本身不负责 iText7 中的边框,单元格负责。 You need to set every cell to be borderless if you want a borderless table (or set the outer cells to have no border on the edge if you still want inside borders).如果您想要一个无边框表格,您需要将每个单元格设置为无边框(如果您仍然想要内部边框,则将外部单元格设置为边缘没有边框)。

Cell cell = new Cell();
cell.add("contents go here");
cell.setBorder(Border.NO_BORDER);
table.addCell(cell);

You could write a method which runs though all children of a Table and sets NO_BORDER.您可以编写一个方法来运行表的所有子项并设置 NO_BORDER。

private static void RemoveBorder(Table table)
{
    for (IElement iElement : table.getChildren()) {
        ((Cell)iElement).setBorder(Border.NO_BORDER);
    }
}

This gives you the advantage that you can still use这为您提供了仍然可以使用的优势

table.add("whatever");
table.add("whatever");
RemoveBorder(table);

instead of changing it on all cells manual.而不是在所有单元格手册上更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM