Search code examples
asposeaspose.wordsaspose.pdf

Aspose.Word - Unable to add more than 10 rows to an existing table from template


With the below code, I'm able to add 10 rows at the max. When i try to add more rows, Aspose is throwing an exception.

Try
    Dim doc As Document = New Document("C:\Users\reddy\Desktop\Junk\Out.doc")
    Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
    For i As Integer = 0 To 10
        Dim clonedRow As Row = DirectCast(table.LastRow.Clone(True), Row)
        For Each cell As Cell In clonedRow.Cells
            cell.CellFormat.Orientation = TextOrientation.Horizontal
            cell.CellFormat.WrapText = True
            cell.CellFormat.FitText = True
            cell.FirstParagraph.Runs.Clear()
            cell.FirstParagraph.AppendChild(New Aspose.Words.Run(doc, "hellotext"))
        Next
        ' Add the row to the end of the table.
        table.AppendChild(clonedRow)
    Next

    doc.Save("C:\Users\reddy\Desktop\Junk\Out1.pdf")

Catch x As Exception
    Dim y As String = ""
End Try

Exception: [Exception[1]

Stack Trace:

   at System.Collections.ArrayList.get_Item(Int32 index)
   at    .(    , Int32 , Boolean )
   at    .(ArrayList , Boolean )
   at    .(ArrayList , Int32 )
   at    .(ArrayList ,    , Int32 , Boolean , Boolean )
   at    . (Table )
   at    .(Table , Boolean )
   at    .(Table , Stack , Boolean )
   at    .VisitTableEnd(Table )
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at    .(    )
   at    .(Document , ​   )
   at    .(    ,     )
   at    .      (    )
   at    .      (    )
   at Aspose.Words.Document.(Stream , String , SaveOptions )
   at Aspose.Words.Document.Save(String fileName)
   at WindowsApplication1.IMPlanSetupTest.newpdfgen() in C:\Projects\BFL\Source\BFL.WindowsApplication1\IMPlanSetupTest.vb:line 63

I'm kind of struck with this piece here. When i change For i As Integer = 0 To 10 to any number less than 10, It is working.


Solution

  • As @Tilal mentioned above, this limitation is due to evaluation version of aspose. After applying proper license, i'm able to insert 10+ rows into the document.

    Cheers.