MigraDoc 一行两张表
MigraDoc Two Tables in one row
我正在使用 MigraDoc 创建一个报告,该报告可以包含 4 tables,2 行和 2 tables。
我已经尝试了很多不同的方法来完成这个。
1- 我尝试在 table.
上创建一个 leftIndent
table1.Format.LeftIndent = 7;
- 我尝试在 table 的行上创建一个 leftIndent。
tables.Rows.LeftIndent = 5;
- 我也试过创建一个 table 并将每个 table 插入到一个单独的单元格中,但我不确定如何放置在 [= 中创建 table 的方法32=] 单元格。
如果我能就此获得任何帮助或意见,我将不胜感激。
谢谢!
我没有看到任何问题。 ;-)
回复 3:已知有一种将表格添加到表格的技巧:将 TextFrame 添加到 Cell,然后将 Table 添加到 TextFrame。
单元格不能分到下一页,因此内表必须足够小以适合一页。
跟随 this post 我能够做到这一点:
我有 4 个 table 是这样的:
Table table = new Table();
table.Borders.Width = 0.75;
Column column = table.AddColumn(Unit.FromCentimeter(6));
column.Format.Alignment = ParagraphAlignment.Left;
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.AddParagraph("some value on first row");
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("another value on second row");
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("The value on third row");
假设我们将这些 table 称为 table、table2、table3 和 table4。
我们可以像这样在 MigraDoc 的一行单元格中插入 table:
Document document = new Document();
Table TableContainer = new Table();
Column columnC = TableContainer.AddColumn(Unit.FromCentimeter(7));
TableContainer.AddColumn(Unit.FromCentimeter(7));
Row rowC = TableContainer.AddRow();
Cell cellC = rowC.Cells[0];
cellC.AddParagraph("First Column");
cellC = rowC.Cells[1];
cellC.AddParagraph("Second Column");
rowC = TableContainer.AddRow();
cellC = rowC.Cells[0];
cellC.Elements.Add(table);
cellC = rowC.Cells[1];
cellC.Elements.Add(table2);
rowC = TableContainer.AddRow();
cellC = rowC.Cells[0];
cellC.Elements.Add(table3);
cellC = rowC.Cells[1];
cellC.Elements.Add(table4);
document.LastSection.Add(TableContainer);
我正在使用 MigraDoc 创建一个报告,该报告可以包含 4 tables,2 行和 2 tables。
我已经尝试了很多不同的方法来完成这个。
1- 我尝试在 table.
table1.Format.LeftIndent = 7;
- 我尝试在 table 的行上创建一个 leftIndent。
tables.Rows.LeftIndent = 5;
- 我也试过创建一个 table 并将每个 table 插入到一个单独的单元格中,但我不确定如何放置在 [= 中创建 table 的方法32=] 单元格。
如果我能就此获得任何帮助或意见,我将不胜感激。 谢谢!
我没有看到任何问题。 ;-)
回复 3:已知有一种将表格添加到表格的技巧:将 TextFrame 添加到 Cell,然后将 Table 添加到 TextFrame。
单元格不能分到下一页,因此内表必须足够小以适合一页。
跟随 this post 我能够做到这一点:
我有 4 个 table 是这样的:
Table table = new Table();
table.Borders.Width = 0.75;
Column column = table.AddColumn(Unit.FromCentimeter(6));
column.Format.Alignment = ParagraphAlignment.Left;
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.AddParagraph("some value on first row");
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("another value on second row");
row = table.AddRow();
cell = row.Cells[0];
cell.AddParagraph("The value on third row");
假设我们将这些 table 称为 table、table2、table3 和 table4。
我们可以像这样在 MigraDoc 的一行单元格中插入 table:
Document document = new Document();
Table TableContainer = new Table();
Column columnC = TableContainer.AddColumn(Unit.FromCentimeter(7));
TableContainer.AddColumn(Unit.FromCentimeter(7));
Row rowC = TableContainer.AddRow();
Cell cellC = rowC.Cells[0];
cellC.AddParagraph("First Column");
cellC = rowC.Cells[1];
cellC.AddParagraph("Second Column");
rowC = TableContainer.AddRow();
cellC = rowC.Cells[0];
cellC.Elements.Add(table);
cellC = rowC.Cells[1];
cellC.Elements.Add(table2);
rowC = TableContainer.AddRow();
cellC = rowC.Cells[0];
cellC.Elements.Add(table3);
cellC = rowC.Cells[1];
cellC.Elements.Add(table4);
document.LastSection.Add(TableContainer);