【问题标题】:iTextSharp : merge the last column (Colspan)iTextSharp:合并最后一列(Colspan)
【发布时间】:2011-11-17 12:31:58
【问题描述】:

我有一张桌子,这张桌子有 3 列。在每一列中,都有一个如图所示的表格。 我做了一个生成表的方法,这个方法在参数中接收一个列表并循环它到 将单元格添加到表格中

我希望一行有 a 而不是 5 列 ... 1 + 1(colspan of 4)。当我做一个colspan 前 4 个已合并,我想最后合并 4 个并保留第一个。

我该怎么做?

谢谢,

【问题讨论】:

    标签: c# reporting itextsharp


    【解决方案1】:

    您只需按照您希望它们跨越的顺序将单元格添加到表格中。如果您在第一个单元格之前添加跨单元格,那么它们就是这样显示的。

    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");
    

    【讨论】:

      【解决方案2】:
              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");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-20
        • 1970-01-01
        • 2013-10-25
        • 2012-10-22
        • 1970-01-01
        • 2014-10-07
        • 2013-03-09
        • 2023-03-22
        相关资源
        最近更新 更多