简体   繁体   English

.Net的Aspose.Words将表格插入表格单元格

[英]Aspose.Words for .Net insert a table into a table cell

I have a C# .Net Windows app. 我有一个C#.Net Windows应用程序。 We are using Aspose.Words to generate a document from our data. 我们正在使用Aspose.Words从我们的数据生成文档。 Insied this document is a main table containg several rows. 该文件是一个包含几行的主表。 We have a requirement to insert another table inside one of the cells on the main table. 我们需要在主表中的一个单元格内插入另一个表。 I'm not seeing how to do that. 我不知道该怎么做。 I have looked for InsertTable(), tried appending the table to be insertted as a Table Node. 我一直在寻找InsertTable(),尝试追加要插入的表作为表节点。 I've tried using the document builder to MoveTo() the cell where I want to put the table. 我尝试使用文档构建器将ToMove()放在要放置表格的单元格中。 So far no dice. 到目前为止,还没有骰子。 Ideas? 有想法吗?

EDIT: the Table objects being used are Aspose.Words.Tables.Table objects 编辑:正在使用的表对象是Aspose.Words.Tables.Table对象

Try the below example, it worked with the latest release at my end. 尝试下面的示例,它可以与最新版本一起使用。 The first table is created in document. 第一个表在文档中创建。 Second table is created inside the cell of first table. 在第一个表的单元格内创建第二个表。

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);

Output document looks like 输出文件看起来像 输出文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM