Documents for Excel, Java Edition Documentation
Features / Table / Add and Delete Table Columns and Rows
In This Topic
    Add and Delete Table Columns and Rows
    In This Topic

    GcExcel Java provides users with the ability to insert and delete columns and rows of a table using the methods of the following interfaces:

    Add and delete table columns

    To add and delete table columns, you can use the add method of the ITableColumns interface and the delete method of the ITableColumn interface respectively.

    In order to add and delete table columns, refer to the following example code.

    Java
    Copy Code
    //Create first table
    ITable table = worksheet.getTables().add(worksheet.getRange("D3:I6"), true);
    
    // Insert a table column before first column.
    table.getColumns().add(0);
    
    // Insert a table column before second column.
    table.getColumns().add(1);
    
    // Delete the first table column.
    worksheet.getTables().get(0).getColumns().get(0).delete();
    
    // Delete the second table column.
    worksheet.getTables().get(0).getColumns().get(1).delete();

    Add and delete table rows

    To add and delete table rows, you can use the add method of the ITableRows interface and the delete method of the ITableRow interface respectively.

    In order to add and delete table rows, refer to the following example code.

    Java
    Copy Code
    //Create first table
    ITable table = worksheet.getTables().get(0);
    
    // insert table row in last row.
    table.getRows().add();
    
    // delete second table row.
    table.getRows().get(1).delete();