Aspose.Word - 将行添加到 VB.Net 中现有的 table

Aspose.Word - Adding rows to an existing table in VB.Net

在 Word 模板文档中,我定义了一个 table header,我想使用 aspose 以编程方式将数据(多行)添加到相同的 table,但遇到了困难在这样做时。

我在网上发现很少有 post 用于执行此操作,但它们都是写的 JAVA 并且这些 post 中使用的函数在 [=25] 中不可用=].

https://www.aspose.com/community/forums/thread/648997/reg-adding-rows-dynamically-to-the-existing-table-in-the-document.aspx

getLastRow() 函数在 Table Class 中不存在。(从上面 post)。

有人可以指点我正确的文档或为我的问题提供解决方案吗? 提前致谢!

请使用 LastRow 方法获取 VB 中 table 的最后一行,使用 Aspose.Words for .NET 17.3。请查看完整代码如下。

我是 Aspose 的开发人员布道师 Tilal Ahmad。

Dim doc As New Document("input.docx")
' Retrieve the first table in the document.
Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
table.FirstRow.RowFormat.HeadingFormat = True
For i As Integer = 1 To 15
' Clone the last row in the table.
Dim clonedRow As Row = DirectCast(table.LastRow.Clone(True), Row)
clonedRow.RowFormat.HeadingFormat = False
' Remove all content from the cloned row's cells. This makes the row ready for
' new content to be inserted into.
For Each cell As Cell In clonedRow.Cells
    cell.FirstParagraph.Runs.Clear() 
    cell.CellFormat.ClearFormatting()
    cell.FirstParagraph.AppendChild(New Run(doc, "hello text"))
Next

' Add the row to the end of the table.

table.AppendChild(clonedRow)
Next

doc.Save("Table.AddCloneRowToTable Out.doc")