iTextSharp - 表函数中的错误?

时间:2010-02-23 21:04:02

标签: itext

我尝试制作这样的表:

PdfPTable Table = new PdfPTable(6);

PdfPCell Cell = new PdfPCell(new Phrase("a", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("b", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("c", Font1));
Cell.Colspan = 2;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("d", Font1));
Cell.Colspan = 2;
Table.AddCell(Cell);

工作正常。但是改变列数会破坏表格。这是一个错误还是我做错了什么?

此代码会破坏表格:

PdfPTable Table = new PdfPTable(17);

PdfPCell Cell = new PdfPCell(new Phrase("a", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("b", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 10;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("c", Font1));
Cell.Colspan = 5;
Table.AddCell(Cell);

Cell = new PdfPCell(new Phrase("d", Font1));
Cell.Colspan = 5;
Table.AddCell(Cell);

编辑:表格应具有以下布局:

|-------------------------------------------------------|
| Cell "a" with | Cell "b" with | Cell "c", colspan = 5 |
| colspan = 2   | colspan = 10  |-----------------------|
| rowspan = 2   | rowspan = 2   | Cell "d", colspan = 5 |
|-------------------------------------------------------|

1 个答案:

答案 0 :(得分:1)

添加Table.CompleteRow();作为最后一行。