Table Rowspan 问题 flowdocument C#

Table Rowspan issue flowdocument C#

我正在尝试使用流文档打印 table,行跨度为 属性。

我正在尝试打印以下输出,

但它给了我这个

我不明白我的代码有什么问题,也许我错过了什么。 任何帮助appreciated.Please请参阅下面的代码,

Table tbl = new Table();
            for (int i = 0; i < 2; i++)
            {
                TableColumn tableCol = new TableColumn();
                tableCol.Width = new GridLength(150);
                tbl.Columns.Add(tableCol);
            }

            TableRow row = new TableRow();
            row.Background = Brushes.White;
            row.FontSize = PointsToPixels(TITLETEXTSIZE);
            row.FontFamily = new FontFamily(FONTFAMILY);


            row.Cells.Add(new TableCell(new Paragraph(new Run("cell1"))));
            row.Cells[0].BorderBrush = Brushes.Black;
            row.Cells[0].BorderThickness = new Thickness(0.0, 1.0, 1, 0.0);
            row.Cells[0].RowSpan = 2;

            row.Cells.Add(new TableCell(new Paragraph(new Run("cell2"))));
            row.Cells[1].BorderBrush = Brushes.Black;
            row.Cells[1].BorderThickness = new Thickness(0.0, 0.0, 0, 1.0);
            row.Cells[1].RowSpan = 1;

            var rowgroup = new TableRowGroup();
            rowgroup.Rows.Add(row);
            tbl.RowGroups.Add(rowgroup);


            row = new TableRow();
            row.Background = Brushes.White;
            row.FontSize = PointsToPixels(TITLETEXTSIZE);
            row.FontFamily = new FontFamily(FONTFAMILY);

            row.Cells.Add(new TableCell(new Paragraph(new Run("cell1"))));
            row.Cells[0].BorderBrush = Brushes.Black;
            row.Cells[0].BorderThickness = new Thickness(0.0, 1.0, 1, 1.0);
            row.Cells[0].RowSpan = 1;

            rowgroup = new TableRowGroup();
            rowgroup.Rows.Add(row);
            tbl.RowGroups.Add(rowgroup);

            tbl.BorderThickness = new Thickness(1, 1, 1, 0);
            tbl.BorderBrush = Brushes.Black;

这是 xaml 中的快速尝试,在构建流文档时,在 C# 中也需要遵循同样的做法。

尝试添加 table 行组并添加 table 行。

    <FlowDocument>
            <Table>
                <TableRowGroup>
                    <TableRow>
                        <TableCell Background="Green" RowSpan="2">
                            <Paragraph>Cell 1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph Background="Yellow">Cell 2</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell Background="Red">
                            <Paragraph>Cell 1</Paragraph>
                        </TableCell>

                    </TableRow>
                </TableRowGroup>
            </Table>
    </FlowDocument>