Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Jul 14, 2020 8:31 pm

Hi. I have this document where I have placed a table with 1 row, 1 cell.

I use this table to control where I "merge" other existing tables into like "Product description tables".

Document is my "working document", documenttable is a document with products.

' Get main table
Dim MainTable As Table = TryCast(document.Sections(0).Tables(MainTableIndex), Table)
'Get specific product table
Dim TempTable As Table = documenttable.Sections(0).Tables(Index of product)
'Make new row in main table
Dim Row As TableRow = MainTable.AddRow()
'Merge product table into row
Row.Cells(0).AddParagraph().AddTable(TempTable)
'''' not working.... need some other way of doing it.

'Add new row to main table
MainTable.Rows.Insert(MainTable.Rows.Count - 1, Row)

So all I want to do is to add a table into existing table cell like a nested table.

What to do (C# or VB doesn't matter)

ThomasBojer
 
Posts: 3
Joined: Mon Mar 02, 2020 8:47 am

Wed Jul 15, 2020 2:54 am

Hello,

Thanks for your inquiry.
The following is the sample code for your reference. If there is any question, please feel free to write back.
Code: Select all
        Dim document As Document = New Document
        document.LoadFromFile("working document.docx")
        Dim MainTable As Table = CType(document.Sections(0).Tables(0), Table)
        Dim documenttable As Document = New Document
        documenttable.LoadFromFile("document with products.docx")
        Dim ProductTable As Table = CType(documenttable.Sections(0).Tables(0), Table)

        Dim row As TableRow = MainTable.AddRow
        'Add ProductTable to MainTable
        row.Cells(0).Tables.Add(ProductTable.Clone)
        document.SaveToFile("out.docx")


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Jul 15, 2020 6:44 am

So simple... tried almost everything... works perfectly.. thanks..

ThomasBojer
 
Posts: 3
Joined: Mon Mar 02, 2020 8:47 am

Wed Jul 15, 2020 7:31 am

Hello,

Thanks for your prompt response.
Feel free to contact us if you need further assistance. Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc