如何填充表的第二列

本文关键字:二列 填充 何填充 | 更新日期: 2023-09-27 18:17:04

我有一个循环,这样它创建表单元格和行,并将其添加到我的表。我唯一的问题是试图添加值专门为我的第二列。

下面是1列

的工作代码
Table table = new Table();
foreach (var collateral in universalDTO.Collaterals)
{
    Span span = new Span("First Column");
    Paragraph paragraph = new Paragraph();
    paragraph.Inlines.Add(span);
    TableCell cell = new TableCell();
    cell.Blocks.Add(paragraph);
    TableRow row = new TableRow();
    row.Cells.Add(cell);
    table.AddRow(row);
}

我想做的是,但它似乎只是在下面添加值,而不是将其添加到右边的新列。

Table table = new Table();
foreach (var collateral in universalDTO.Collaterals)
{
    Span span = new Span("First Column");
    Paragraph paragraph = new Paragraph();
    paragraph.Inlines.Add(span);
    Span span2 = new Span("Second Column");
    Paragraph paragraph2 = new Paragraph();
    paragraph.Inlines.Add(span2);
    TableCell cell = new TableCell();
    cell.Blocks.Add(paragraph);
    TableCell cell2 = new TableCell();
    cell2.Blocks.Add(paragraph2);
    TableRow row = new TableRow();
    row.Cells.Add(cell);
    row.Cells.Add(cell2);
    table.AddRow(row);
}

我也试过table.AddColumn(),但那不起作用。任何帮助或建议将是伟大的。

我想让我的表看起来像下面

Table:
First Column    Second Column
First Column    Second Column
First Column    Second Column
First Column    Second Column

如何填充表的第二列

Table table = new Table();
foreach (var collateral in universalDTO.Collaterals)
{
Span span = new Span("First Column");
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(span);
Span span2 = new Span("Second Column");
Paragraph paragraph2 = new Paragraph();
paragraph2.Inlines.Add(span2);
TableCell cell = new TableCell();
cell.Blocks.Add(paragraph);
TableCell cell2 = new TableCell();
cell2.Blocks.Add(paragraph2);
TableRow row = new TableRow();
row.Cells.Add(cell);
row.Cells.Add(cell2);
table.AddRow(row);
}