aspose.words 如何在不规则table中插入行
时间: 2023-12-19 07:05:53 浏览: 27
您可以使用Aspose.Words提供的Table类的InsertAfter和InsertBefore方法在不规则表格中插入行。以下是示例代码:
```
Document doc = new Document("input.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
Row newRow = new Row(doc);
newRow.Cells.Add(new Cell(doc));
newRow.Cells.Add(new Cell(doc));
// Insert new row after the first row
Row firstRow = table.Rows[0];
table.InsertAfter(newRow, firstRow);
// Insert new row before the last row
Row lastRow = table.LastRow;
table.InsertBefore(newRow, lastRow);
```
在上面的示例中,我们首先获取文档中的第一个表格。然后,我们创建一个新的行并将其添加到表格中。最后,我们使用InsertAfter和InsertBefore方法将新行插入到不规则表格中的特定位置。
请注意,如果您要在表格的开头或结尾插入行,则必须使用InsertBefore或InsertAfter方法,而不是InsertAfterSelf或InsertBeforeSelf方法。这是因为不规则表格的第一行和最后一行可能不是TableRow对象。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)