Hello,
I work in VB.NET and I have an issue with my nested table. I created a table which have 1 row and 3 cells. I wanted to add a nested table to the last cell but my tries never succeed, it just add it to the first cell. For the moment in my real code I have a function which take a cell (by reference) to fill it with my nested table. I must keep this function if possible.
Can you held me please?
Here’s my code
’ Instantiate an object PDF class
Dim license As License = New License
license.SetLicense(“Aspose.Total.lic”)
Dim Doc = New Pdf
’ add the section to PDF document sections collection
Dim section As Aspose.Pdf.Section = New Section(Doc)
Doc.Sections.Add(section)
'Instantiate a table object
Dim table1 As Table = New Table(section)
'Add the table in paragraphs collection of the desired section
section.Paragraphs.Add(table1)
table1.ColumnWidths = “100 10 100”
table1.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F)
table1.Border = New BorderInfo(BorderSide.All, 1.0F)
'Create rows in the table and then cells in the rows
Dim row1 As Row = table1.Rows.Add()
Dim cell As Cell = row1.Cells.Add
Dim row12 As Row = table1.Rows.Add()
Dim cell12 As Cell = row1.Cells.Add
Dim row13 As Row = table1.Rows.Add()
Dim cell13 As Cell = row1.Cells.Add
'I try to add my nested table to the last cell (in comment the other thing I tried)
Dim nestedTable As Table = New Table(cell13) 'New Table(table1.Rows(0).Cells(1))
cell.Paragraphs.Add(nestedTable)
nestedTable.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F, New Color(“red”))
nestedTable.Border = New BorderInfo(BorderSide.All, 1.0F, New Color(“red”))
Dim row2 As Row = nestedTable.Rows.Add()
Dim text2 As Text = New Text()
Dim cell2 As Cell = row2.Cells.Add()
cell2.Paragraphs.Add(text2)
Dim seg2 As Segment = text2.Segments.Add()
seg2.Content = “1”
Doc.Save(“D:/NestedTableTest.pdf”)
And you can find my test file attached.
Hello Anouck,
Thanks for using our products and sorry for replying you late.
The nested table is being added to first cell because you have added the nested table to paragraphs collection of first cell in the row. Please update the code as specified below to resovle this problem.
'I try to add my nested table to the last cell (in comment the other thing I tried)
Dim nestedTable As Table = New Table(cell13) 'New Table(table1.Rows(0).Cells(1))
cell.Paragraphs.Add(nestedTable)
change it to
cell13.Paragraphs.Add(nestedTable)
I have also attached the resultant PDF that I have generated after the code has been updated. In case you still face any problem or you have any further query, please feel free to contact.
I have tested the scenario using Aspose.Pdf for .NET 4.8.0.
Thanks, I haven’t seen it !