Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
646 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...