问题
I would like to add a table inside another table (inside a specific cell).
I can't find a way to add a Table
object to a Cell
object.
Is that simply impossible?
Alternatively, I may merge some cells, but I can't find any sample in MigraDoc website with cells merging.
Here is my code :
Table parentTable = new Table();
parentTable.AddColumn(Unit.FromCentimeter(9));
Row parentRow = parentTable.AddRow();
Cell parentCell = parentRow.Cells[0];
Table currentTable = new Table();
currentTable.AddColumn(Unit.FromCentimeter(4));
Row currentRow = currentTable.AddRow();
currentRow.Cells[0].AddParagraph("blablabla");
parentCell.Add(currentTable); // this does not work
回答1:
The Invoice sample uses merging:
http://www.pdfsharp.net/wiki/Invoice-sample.ashx
The keywords are MergeRight and MergeDown. Use MergeRight=1
to get a cell that spans two columns.
I think merging is the best approach if it does not get too complicated.
You can add TextFrame
to a Cell
and add a Table
to a TextFrame
to achieve nested tables. However you will have to deal with the row height as the table cell will not grow automatically when the contents of the TextFrame grow.
There is a trick to add a Table
to a Cell
or Paragraph
in a cell using the generic Add
method.
Code hack that adds a table to a table cell:
parentCell.Elements.Add(currentTable);
This is an undocumented feature. Merging is the recommended approach.
Cells do not break to the next page, so adding tables to cells will work for small nested tables only.
来源:https://stackoverflow.com/questions/36303719/migradoc-imbricated-nested-tables