Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

c# - MigraDoc - imbricated / nested tables?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...