Split cell?

Hello,
I wanted to know if it is possible to split cell R1C1 (see picture) into X other cell without changing the width of the table

During my tests, some cells added that were outside the table on the right.

I must be making a mistake, can you point me in the right direction?

Thank You

@Alcyon71 You can achieve this using code like the following:

Document doc = new Document(@"C:\Temp\in.docx");

Table table = doc.FirstSection.Body.Tables[0];

// Get Cell we need to split.
Cell cell = table.Rows[1].Cells[0];
Cell newCell = (Cell)cell.Clone(false);

// Set new width.
cell.CellFormat.Width /= 2;
newCell.CellFormat.Width /= 2;

// Insert the next cell.
cell.ParentNode.InsertAfter(newCell, cell);

// Autofit the table to the column width.
table.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(@"C:\Temp\out.docx");

You should call Table.AutoFit method to force table grid recalculation to get the desired output.
in.docx (12.6 KB)
out.docx (10.0 KB)

Hello,
Thanks it works!!

Bets regards

1 Like