Deleting a column from a table


I need to iterate through several tables in a Document and remove the fourth column from them.

Although Table objects have a .Rows collection, I can’t seem to find an equivalent .Columns collection - is that correct?

I was hoping to use something like:

((Aspose.Words.Tables.Table) doc.GetChildNodes(NodeType.Table, true)[table]).Columns.Remove(3);

Any assistance gratefully received.


Thanks for your request. There is no “column” concept in the Word table. By Microsoft Word design rows in a table in a Microsoft Word document are completely independent. It means each row can have any number of cells of any width.
Please see the following code example which demonstrates how to remove table column:

// Open source document
Document doc = new Document("in.doc");
// Get BookMark node
Node bmNode = doc.Range.Bookmarks["RemoveThisColumn"].BookmarkStart;
if (((Paragraph) bmNode.ParentNode).ParentNode.NodeType == NodeType.Cell)
    // Get cell with bookmark
    Cell cell = (Cell)(((Paragraph) bmNode.ParentNode).ParentNode);
    // Get index of cell
    int cellIndex = cell.ParentRow.IndexOf(cell);
    // Remove all cells with cellIndex
    foreach(Row row in cell.ParentRow.ParentTable)

Bookmark “RemoveThisColumn” is located in first Cell of the “column”.

1 2 3 4 5 Bookmark is here 6 7

Best regards,

There is no “column” concept in the Word table.

That’s what I thought. Thanks for the code - works perfectly.