iTextSharp:合并最后一列(Colspan)

问题描述 投票:3回答:2

我有一个表,该表有3列。在每一列中,都有一张类似图片的表格。我做了一个生成表的方法,该方法接收参数列表并循环到表中的addCell

我想一行有5列而不是5列... 1 + 1(colspan为4)。当我做一个colspan首先合并4个,我想合并最后4个并保留第一个。

我该怎么做?

谢谢,

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9FOWJQVi5wbmcifQ==” alt =“在此处输入图像描述”>“在此处输入图像描述”

c# reporting itextsharp
2个回答
10
投票

您只需要按照它们要跨越的顺序将单元格添加到表中。如果在第一个单元格之前添加跨度单元格,则它们将以这种方式显示。

PdfPTable t = new PdfPTable(5);
//Row 1
t.AddCell("R1C1");
t.AddCell("R1C2");
t.AddCell("R1C3");
t.AddCell("R1C4");
t.AddCell("R1C5");

//Row 2 - One regular cell followed by four spanned cells
t.AddCell("R2C1");
t.AddCell(new PdfPCell(new Phrase("R2C2-5")) { Colspan = 4 });

//Row 3 - Four spanned cells followed by one regular cell
t.AddCell(new PdfPCell(new Phrase("R3C1-4")) { Colspan = 4 });
t.AddCell("R3C5");

0
投票
        table.AddCell("Row 1, Col 1");
        table.AddCell("Row 1, Col 2");
        table.AddCell("Row 1, Col 3");

        table.AddCell("Row 2, Col 1");
        table.AddCell(new PdfPCell(new Phrase("R2, C2")) { Colspan = 2 }); // table.AddCell("Row 2, Col 2");
        //table.AddCell("Row 2, Col 3");

        table.AddCell(new PdfPCell(new Phrase("R3, C1")) { Rowspan = 2 }); //table.AddCell("Row 3, Col 1");
        table.AddCell("Row 3, Col 2");
        table.AddCell("Row 3, Col 3");

        //table.AddCell("Row 4, Col 1");
        table.AddCell("Row 4, Col 2");
        table.AddCell("Row 4, Col 3");
© www.soinside.com 2019 - 2024. All rights reserved.