Aspose.Word - 无法从模板向现有 table 添加超过 10 行
Aspose.Word - Unable to add more than 10 rows to an existing table from template
使用下面的代码,我最多可以添加 10 行。当我尝试添加更多行时,Aspose 抛出异常。
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
异常:
[
堆栈跟踪:
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 的数字时,它正在工作。
正如@Tilal 上面提到的,这个限制是由于 aspose 的评估版本。申请适当的许可证后,我可以在文档中插入 10 多行。
干杯。
使用下面的代码,我最多可以添加 10 行。当我尝试添加更多行时,Aspose 抛出异常。
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
异常:
[
堆栈跟踪:
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 的数字时,它正在工作。
正如@Tilal 上面提到的,这个限制是由于 aspose 的评估版本。申请适当的许可证后,我可以在文档中插入 10 多行。
干杯。