简体   繁体   中英

Add Table to FlowDocument In Code Behind

I have tried this.....

_doc = new FlowDocument();

Table t = new Table();
for (int i = 0; i < 7; i++)
{
    t.Columns.Add(new TableColumn());
}

TableRow row = new TableRow();
row.Background = Brushes.Silver;
row.FontSize = 40;
row.FontWeight = FontWeights.Bold;

row.Cells.Add(new TableCell(new Paragraph(new Run("I span 7 columns"))));
row.Cells[0].ColumnSpan = 6;

_doc2.Blocks.Add(t);

When I go to view this document the table never shows.....although the border image and document title that I add to this document before adding this table outputs fine.

You add the Columns to the Table, but where is the code that adds the row? It just isn't connected.

Add something like:

...
var rg = new TableRowGroup();
rg.Rows.Add(row);
t.RowGroups.Add(rg);
_doc2.Blocks.Add(t);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM