1

ライブラリを使用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;
}
4

1 に答える 1