Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Range Operations / Insert and Delete Rows and Columns
In This Topic
    Insert and Delete Rows and Columns
    In This Topic

    DsExcel Java provides you with the ability to insert or delete rows and columns in a worksheet.

    Insert rows and columns

    DsExcel Java allow you to add rows or columns in a worksheet by calling the insert method of the IRange interface.

    When rows are added, the existing rows in the worksheet are shifted in downward direction whereas when columns are added, the existing columns in the worksheet are shifted to the right.

    You can also use the getEntireRow method to insert rows in a worksheet which includes all the columns. While inserting rows using the getEntireRow method, there is no need to provide the shift direction in the function parameters. If you provide the same, it will be ignored.

    In order to insert rows in a worksheet, refer to the following example code.

    Java
    Copy Code
    // Insert rows
    worksheet.getRange("A3:A5").getEntireRow().insert();
    // OR
    worksheet.getRange("3:5").insert();

    You can also use the getEntireColumn method to insert columns in the worksheet which includes all rows. While inserting columns using the EntireColumn method, there is no need to provide the shift direction in the function parameters. If you provide the same, it will be ignored.

    In order to insert columns in a worksheet, refer to the following example code.

    Java
    Copy Code
    // Insert columns
    worksheet.getRange("A3:A5").getEntireColumn().insert();
    // OR
    worksheet.getRange("3:5").insert();

    Delete row and column

    DsExcel Java allows you to delete rows or columns in the worksheet by calling the delete method of the IRange interface.

    When rows are deleted, the existing rows in the worksheet are shifted in upwards direction, whereas when columns are deleted, the existing columns in the worksheet are shifted to the left.

    In order to delete rows from the worksheet, refer to the following example code.

    Java
    Copy Code
    // Delete rows
    worksheet.getRange("A3:A5").getEntireRow().delete();
    // OR
    worksheet.getRange("3:5").delete();

    In order to delete columns from the worksheet, refer to the following example code.

    Java
    Copy Code
    // Delete columns
    worksheet.getRange("A3:A5").getEntireColumn().delete();
    // OR
    worksheet.getRange("3:5").delete();

    See Also