MigraDoc-嵌入/嵌套表格? [英] MigraDoc - imbricated / nested tables?

查看:87
本文介绍了MigraDoc-嵌入/嵌套表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个表内(特定单元格内)添加一个表。
我找不到将 Table 对象添加到 Cell 对象的方法。
难道这根本不可能吗?

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?

或者,我可以合并一些单元格,但是在MigraDoc网站上找不到任何带有单元格合并的样本。

Alternatively, I may merge some cells, but I can't find any sample in MigraDoc website with cells merging.

这是我的代码:

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


推荐答案

发票示例使用合并:

http://www.pdfsharp.net/wiki/Invoice -sample.ashx

关键字为MergeRight和MergeDown。使用 MergeRight = 1 可以得到一个跨越两列的单元格。

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.

您可以将 TextFrame 添加到 Cell 并将 Table 添加到 TextFrame 以获得嵌套表。但是,由于TextFrame的内容增长时表格单元格不会自动增长,因此您将不得不处理行高。

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.

有一种技巧可以添加表格到单元格中的 Cell Paragraph 的单元格中,并使用通用添加方法。
将表添加到表单元格的代码黑客:

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.

这篇关于MigraDoc-嵌入/嵌套表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆