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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: DocIO |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon