【问题标题】:Aspose.Word - Adding rows to an existing table in VB.NetAspose.Word - 在 VB.Net 中向现有表中添加行
【发布时间】:2017-03-29 22:40:13
【问题描述】:

在一个 Word 模板文档中,我定义了一个表头,并希望使用 aspose 以编程方式将数据(多行)添加到同一个表中,并且很难做到这一点。

我在网上找到了一些关于这样做的帖子,但它们都是用 JAVA 编写的,并且这些帖子中使用的函数在 VB.Net 中不可用。

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

getLastRow() 函数在 Table Class 中不存在。(来自上面的帖子)。

谁能指出我正确的文档或为我的问题提供解决方案。 提前致谢!

【问题讨论】:

    标签: vb.net aspose aspose.words


    【解决方案1】:

    请使用 LastRow 方法在 VB 中使用 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")
    

    【讨论】:

    • 这在我添加 10 行时有效,但在那之后它失败了。
    • 异常消息:索引超出范围。必须是非负数且小于集合的大小。参数名称:索引
    • 异常堆栈:在 Aspose.Words.Document.Save(String fileName) at Aspose.Words.Document.(Stream, String, SaveOptions) at WindowsApplication1.IMPlanSetupTest.newpdfgen() in C:\Projects \BFL\Source\BFL.WindowsApplication1\IMPlanSetupTest.vb:第 65 行
    • 在 Aspose.Words.CompositeNode 的 Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor 访问者)。Aspose.Words.CompositeNode 的AcceptCore(DocumentVisitor 访问者)。 .AcceptCore(DocumentVisitor visitor) at    .(    ) at    .(Document ,    ) at    .(    ,     ) at    。 ( ) 在 。 (   )
    • 由于评估版本,您遇到了问题。请注意 Aspose.Words 的评估版(未指定许可证)提供完整的产品功能,但它会在打开和保存时在文档顶部插入评估水印,并将最大文档大小限制为数百段。请申请30 days temporary license 并申请,它将解决问题。
    猜你喜欢
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2019-06-24
    • 2023-03-25
    • 2017-10-02
    相关资源
    最近更新 更多