Add new row with different cell number

Hi Friends!

I want to add new row in table, but with different cell numbers:
I have three cell in last row and I want to remove this row and add row with only two cell

Please, can You help me

Thank You in advance

@levanq,

Please ZIP and attach your input Word document and the expected document showing the correct output here for testing. You can create expected document by using MS Word. We will then investigate the scenario on our end and provide you code to achieve the same by using Aspose.Words.

Documents.zip (27.0 KB)

@levanq,

One way to achieve the desired results is as follows:

Document doc = new Document("E:\\Documents\\input.docx");

Table table = doc.FirstSection.Body.Tables[0];
table.LastRow.Remove();

Row newRow = (Row)table.FirstRow.Clone(true);
newRow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
newRow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
newRow.Cells[2].CellFormat.HorizontalMerge = CellMerge.None;

table.AppendChild(newRow);

doc.Save("E:\\Documents\\19.2.docx"); 

Hope, this helps.

1 Like