0

我有一个 C# .Net Windows 应用程序。我们正在使用 Aspose.Words 从我们的数据中生成一个文档。Insied 这个文件是一个包含几行的主表。我们需要在主表的一个单元格中插入另一个表。我不知道该怎么做。我一直在寻找 InsertTable(),尝试将要插入的表附加为表节点。我已经尝试使用文档生成器来 MoveTo() 我要放置表格的单元格。到目前为止还没有骰子。想法?

编辑:正在使用的 Table 对象是 Aspose.Words.Tables.Table 对象

4

1 回答 1

2

试试下面的例子,它适用于我最后的最新版本。第一个表是在文档中创建的。第二个表是在第一个表的单元格内创建的。

Aspose.Words.Document doc = new Aspose.Words.Document();
// Create first table with 1 row and 2 columns
Aspose.Words.Tables.Table table = new Aspose.Words.Tables.Table(doc);
// Add the table to the document.
doc.FirstSection.Body.AppendChild(table);
Aspose.Words.Tables.Row row = new Aspose.Words.Tables.Row(doc);
table.AppendChild(row);
Aspose.Words.Tables.Cell cell1 = new Aspose.Words.Tables.Cell(doc);
row.AppendChild(cell1);
Aspose.Words.Tables.Cell cell2 = new Aspose.Words.Tables.Cell(doc);
row.AppendChild(cell2);
table.SetBorders(LineStyle.Dot, 1, System.Drawing.Color.Red);

// Add the second table in cell1
Aspose.Words.Tables.Table table2 = new Aspose.Words.Tables.Table(doc);
cell1.AppendChild(table2);
Aspose.Words.Tables.Row row2 = new Aspose.Words.Tables.Row(doc);
table2.AppendChild(row2);
Aspose.Words.Tables.Cell cell3 = new Aspose.Words.Tables.Cell(doc);
row2.AppendChild(cell3);
Aspose.Words.Tables.Cell cell4 = new Aspose.Words.Tables.Cell(doc);
row2.AppendChild(cell4);
table2.SetBorders(LineStyle.DotDash, 1, System.Drawing.Color.Blue);

输出文档看起来像 输出文件

于 2014-11-07T18:44:30.490 回答