2017-03-31 48 views
0

使用下面的代碼,我可以在最多添加10行。當我嘗試添加更多行時,Aspose會拋出異常。Aspose.Word - 無法將10行以上的行添加到模板中的現有表中

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[1]

堆棧跟蹤:

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 

我是一種觸動了這件作品在這裏。當我將For i As Integer = 0 To 10更改爲小於10的任何數字時,它正在工作。

+0

這個問題也貼在這裏https://www.aspose.com/community/forums/833824/unable-to-add-more-than-10-rows-to-an-existing-table-from-template /showthread.aspx#833824 – Reddy

+0

您的代碼在10行以上的工作狀態正常。請分享您的源文件以複製該問題。 –

+0

我剛剛測試過其他例子,並且有同樣的問題。 重現此問題的最佳方法是使用大小爲5(行)x1(列)的表創建工作文檔,並嘗試使用上述代碼添加99行。它與上述相同的例外是失敗的。 – Reddy

回答

0

正如上面提到的@Tilal,這個限制是由於評估版aspose。在應用適當的許可證後,我可以在文檔中插入10多行。

乾杯。

相關問題