We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Is it possible to add/remove column from the table ?

 

Yes, it is possible add or delete column from a table. There is no property to directly add or remove columns from the table. By Microsoft Word design rows in a table in a document are completely independent. It means each row can have any number of cells of any width. So if you need to add column from MS Word table you have to add cell for each row in table. So we have to add cell for each row by looping. Please refer the below code snippet to achieve this...>

C#

//To add/remove column into the table

for (int i = 0; i < table.Rows.Count ; i++)

{

WTableCell cell = new WTableCell(document);

cell.AddParagraph().AppendText(i.ToString());

table.Rows[i].Cells.Add(cell);

//or Use Addcell method to add new cell

//table.Rows[i].AddCell().AddParagraph().AppendText(i.ToString());

//Insert colum at specific column

//table.Rows[i].Cells.Insert(table.Rows[i].Cells.Count-1, cell);

//Set width of the cell

table.Rows[i].Cells[2].Width = 50;

table.Rows[i].Cells[3].Width = 50;

//To remove cell from the row

table.Rows[i].Cells.RemoveAt(0);

}

VB

For i As Integer = 0 To table.Rows.Count - 1

''To add/remove column into the table

Dim cell As New WTableCell(document)

cell.AddParagraph().AppendText(i.ToString())

table.Rows(i).Cells.Add(cell)

''or Use Addcell method to add new cell

''table.Rows[i].AddCell().AddParagraph().AppendText(i.ToString());

''Insert colum at specific column

''table.Rows[i].Cells.Insert(table.Rows[i].Cells.Count-1, cell);

''Set width of the cell

table.Rows(i).Cells(2).Width = 50

table.Rows(i).Cells(3).Width = 50

''To remove cell from the row

table.Rows(i).Cells.RemoveAt(0)

Next

Article ID: Published Date: Last Revised Date: Platform: Control:
286 04/30/2011 07/10/2014 Windows Forms DocIO
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.