Free Support Forum - aspose.com

Word table append two columns can't succeed

I want to append two columns from the end of my exist word docx table
but I can’t succeed.
Could anybody help me , Thanks.

my source code is following:

Dim doc As New Document(“d:\test.docx”)
Dim table As Tables.Table = New Tables.Table(doc)
Dim cell As New Cell(doc)

For Each row As Row In table.Rows
row.lastcell.AppendChild(cell)
next

doc.Save(“d:\test1.docx”)

@wujohn,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your sample input Word document
  • Aspose.Words generated output document showing the undesired behavior
  • Your expected document which shows the correct output. Please create this document by using Microsoft Word application. We will provide the code to achieve the same by using Aspose.Words for .NET.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

test.zip (19.2 KB)

attachment is my sample code , test.docx is my original word file , aspose words output file is same .

I want to show as test1.docx word file , Thanks.

@wujohn,

Please try using the following code:

Document doc = new Document(MyDir + @"test\test.docx");

Table tab = (Table)doc.GetChildNodes(NodeType.Table, true)[0];
foreach(Row row in tab)
{
    row.AppendChild(row.LastCell.Clone(false));
    row.AppendChild(row.LastCell.Clone(false));
}          

doc.Save(MyDir + @"test\18.3.docx");

I try it and works perfectly , thanks for your help.