我正在使用iTextSharp
库来生成 PDF 表。
要在每页上重复标题(2 行标题),我使用HeaderRows
的是 PDF 表的属性。它在每一页上重复标题,但在标题下方,它会插入一个额外的具有默认格式的新空白行。这个额外的行不会影响Rowspan
列和行的值。
我怎样才能从表中删除这个额外的行?
IList<Common.rowspan> Row = new List<Common.rowspan>();
for (int i = 0; i < RowsCount; i = i + 5)
{
Row.Add(new Common.rowspan()
{
row = i,
col = 0,
span = 5
});
}
float[] Width = new float[] { 250, 450, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
public PdfPTable GetPdfTable(string Module, DataTable dt, IList<Common.rowspan> row, float[] width, int HeaderRow = 1)
{
PdfPTable table = new PdfPTable(width.Length);
PdfPCell cell;
foreach (DataColumn dc in dt.Columns)
{
cell = new PdfPCell(new Paragraph(dc.Caption));
table.AddCell(cell);
}
int rowindex = 0; int colindex = 0; bool rowskip = false;
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (row[rowindex].row == i)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
cell = new PdfPCell(new Phrase(PageController.DecodeText(dt.Rows[i][j].ToString())));
if (row[rowindex].col == j && !rowskip)
{
cell.Rowspan = row[rowindex].span;
rowskip = true;
colindex = row[rowindex].col;
}
table.AddCell(cell);
}
if (rowindex < row.Count - 1)
rowindex = rowindex + 1;
rowskip = false;
}
else
{
for (int j = 0; j < dt.Columns.Count; j++)
{
if (colindex != j)
{
cell = new PdfPCell(new Phrase(PageController.DecodeText(dt.Rows[i][j].ToString())));
table.AddCell(cell);
}
}
}
}
}
else
{
cell = new PdfPCell(new Phrase("No Record Found.", NoRecordFoundBlackBold_Calibri_11));
cell.Colspan = dt.Columns.Count;
table.AddCell(cell);
}
table.HeaderRows = HeaderRow;
return table;
}