-2

如何在 C# 中使用 itextSharp 在 PDF 中创建具有不同列数、大小的表格。

表格1)

Column1     Column2     Column3     Column4     Column5     Column6

表 2)

Col1        Col2        Col3

它必须看起来像

Column1     Column2     Column3     Column4     Column5     Column6
Col1        Col2        Col3
4

1 回答 1

4

像这样的东西?

    Document doc        = new Document(PageSize.A4);

    PdfPTable aTable                = new PdfPTable(6);
    aTable.HorizontalAlignment      = Element.ALIGN_LEFT;
    aTable.WidthPercentage          = 100;
    aTable.AddCell("Column 1");
    aTable.AddCell("Column 2");
    aTable.AddCell("Column 3");
    aTable.AddCell("Column 4");
    aTable.AddCell("Column 5");
    aTable.AddCell("Column 6");

    doc.Add(aTable);

    PdfPTable tp                    = new PdfPTable(3);
    tp.HorizontalAlignment          = Element.ALIGN_LEFT;
    tp.WidthPercentage              = 50;
    //tp.SetWidths(new []{60f, 20f, 20f});
    tp.AddCell("Col 1");
    tp.AddCell("Col 2");
    tp.AddCell("Col 3");

    doc.Add(tp);
于 2012-12-10T12:40:28.143 回答