Reputation: 2707
I am trying to print table using flow-document,with row-span property.
I am trying to print below output,
but it gives me this
I don't understand what's wrong with my code,maybe i have missed something. Any help appreciated.Please see the code below,
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;
Upvotes: 0
Views: 1681
Reputation: 74
This is a quick try in xaml, the same need to be followed in C# while constructing the Flow Document.
Try to add a table row group and add the table row.
<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>
Upvotes: 1