【问题标题】:How to set no border of nested table?如何设置嵌套表格无边框?
【发布时间】:2012-08-29 13:15:01
【问题描述】:

我有一个包含一些单元格和嵌套表格的表格。

嵌套表周围有边框,但我不知道为什么。

单元格没有边框,因为我添加到单元格和嵌套单元格:

cell.setBorder(Rectangle.NO_BORDER);

然后我将嵌套表添加到表中;

table.addCell(nestedTable());

似乎是嵌套表格周围的单元格有边框。

如何设置为零?

更新:

public static void main(String[] args) {
    Document document = new Document();

    try {
        PdfWriter.getInstance(document, new FileOutputStream("Table2.pdf"));

        document.open();

        PdfPTable table = new PdfPTable(3);

        PdfPCell cell1 = new PdfPCell(new Phrase("Cell 1"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell2 = new PdfPCell(new Phrase("Cell 2"));
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell3 = new PdfPCell(new Phrase("Cell 3"));
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setBorder(Rectangle.NO_BORDER);

        PdfPTable nestedTable = new PdfPTable(2);
        PdfPCell cell4 = new PdfPCell(new Phrase("Nested Cell 1"));
        cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell4.setBorder(Rectangle.NO_BORDER);
        nestedTable.addCell(cell4);

        PdfPCell cell5 = new PdfPCell(new Phrase("Nested Cell 2"));
        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell5.setBorder(Rectangle.NO_BORDER);
        nestedTable.addCell(cell5);

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        table.addCell(nestedTable);
        table.addCell(nestedTable);
        table.addCell(nestedTable);

        document.add(table);

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

【问题讨论】:

  • 你的nestedTable()方法的代码是什么?
  • 已更新有问题。我也更新了表格。
  • 你能把nestedTable()的整个代码,而不仅仅是sn-ps,如果不是太长的话?如果没有清晰的全局视图,很难弄清楚您操作了哪些对象以及如何操作它们...

标签: java border itext


【解决方案1】:

尝试修改主表的默认单元格:

PdfPTable table = new PdfPTable(3);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

请参阅API 了解更多信息。

【讨论】:

  • 嗯,它对我有用。您确定您正在查看正确的生成文档吗?或者您正在运行更新的代码?
  • 它有效,但您必须将边框设置为父表,而不是嵌套表。谢谢@AlexisPigeon
【解决方案2】:

好的,我明白了。

我不能这样做:

    table.addCell(nestedTable);

我需要创建新的单元格并在此单元格内添加嵌套表格,现在我没有边框了

【讨论】:

    【解决方案3】:

    你试过 table.setBorder(Rectangle.NO_BORDER); ??

    【讨论】:

    • pdfTable中没有这个方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多