Export (0) Print
Expand All

How to: Add Rows and Columns to Word Tables

In a Microsoft Office Word table, the cells are organized into rows and columns. You can use the Add method of the Rows object to add rows to the table and the Add method of the Columns object to add columns.

Applies to: The information in this topic applies to document-level projects and application-level projects for Word 2007 and Word 2010. For more information, see Features Available by Office Application and Project Type.

The following code examples can be used in a document-level customization. To use these examples, run them from the ThisDocument class in your project. These examples assume that the document associated with your customization already has at least one table.

To add a row to a table

  • Use the Add method to add a row to the table.

    
    this.Tables[1].Rows.Add(this.Tables[1].Rows[1]);
    
    
    

To add a column to a table

  • Use the Add method, and then use the DistributeWidth method to make all the columns the same width.

    
    this.Tables[1].Columns.Add(this.Tables[1].Columns[1]); 
    this.Tables[1].Columns.DistributeWidth();
    
    
    

The following code examples can be used in an application-level add-in. To use the examples, run them from the ThisAddIn class in your project. These examples assume that the active document already has at least one table.

To add a row to a table

  • Use the Add method to add a row to the table.

    
    this.Application.ActiveDocument.Tables[1].Rows.Add(
        this.Application.ActiveDocument.Tables[1].Rows[1]);
    
    
    

To add a column to a table

  • Use the Add method, and then use the DistributeWidth method to make all the columns the same width.

    
    this.Application.ActiveDocument.Tables[1].Columns.Add(
        this.Application.ActiveDocument.Tables[1].Columns[1]);
    this.Application.ActiveDocument.Tables[1].Columns.DistributeWidth();
    
    
    

Community Additions

ADD
Show:
© 2014 Microsoft