2010-02-23 43 views
0

我尝试做一个表是这样的:iTextSharp - 表函数中的错误?

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

“colspan”的总数大于“PdfPTable”构造函数中的列参数...为什么? – bzlm 2010-02-23 21:07:06

+0

该表应该在左边有2列,rownspan为2.这两个单元的右边应该有2个单元格。 因此,2个右侧单元必须具有相同的colspan,并且总的colspan数大于表的列数。 我认为这是正确的。 – Matthias 2010-02-23 21:14:42

回答

1

添加Table.CompleteRow();作为最后一道防线。