【问题标题】:iText 7 borderless table (no border)iText 7无边框表格(无边框)
【发布时间】:2017-05-27 05:57:32
【问题描述】:

下面这段代码不起作用。

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

我是 iText 7 的新手,我只想让我的表格无边框。 比如怎么做?

【问题讨论】:

    标签: java itext itext7


    【解决方案1】:

    默认情况下,表格本身不负责 iText7 中的边框,单元格负责。如果您想要一个无边框表格,则需要将每个单元格设置为无边框(如果您仍然想要内部边框,则将外部单元格设置为边缘没有边框)。

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

    【讨论】:

    • 我试过这个先生,但在“cell.setBorder(Border.NO_BORDER)”中出现错误,说 CANNOT FIND SYMBOL “NO_BORDER”
    • 对不起我的问题。进口问题。 tnxxx
    • 根据iText 7.1.6,您不能再将String 添加到Cell,只能添加IBlockElementImage
    • iText 7.1.10 与 C# 你可以这样做: .table.AddCell(new Cell().Add(new Paragraph("contents").SetBorder(Border.NO_BORDER)));
    【解决方案2】:

    您可以编写一个方法,通过 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);
    

    而不是在所有单元格手册上更改它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      相关资源
      最近更新 更多