表Rowspan问题flowdocument C#

时间:2015-12-04 04:44:57

标签: c# wpf flowdocument

我正在尝试使用带有行间距属性的flow-document打印表。

我正在尝试打印输出,

enter image description here

但它给了我这个

enter image description here

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

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;

1 个答案:

答案 0 :(得分:1)

这是xaml中的一个快速尝试,在构建Flow文档时需要遵循C#。

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

    <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>

enter image description here