DsExcel Java enables users to insert and delete a cell or a range of cells while working with spreadsheets. This facilitates the customization of worksheets based on specific requirements.
DsExcel Java allows you to add a cell or a range of cells in a worksheets by calling the insert method of the IRange interface. To add a cell or a range of cells, specify the cell range, for example A3 for single cell or A3:A5 for a range of cells.
You can choose from the following options while inserting a cell or a range of cells in a worksheet.
Method | Description |
---|---|
insert | This method automatically inserts a cell or a range of cells. |
insert(InsertShiftDirection.Down) | This method inserts the range of cells and shifts the existing range of cells in downward direction. |
insert(InsertShiftDirection.Right) | This method inserts the range of cells and shifts the existing range of cells to the right. |
In order to insert a single cell and a cell range in the worksheet, refer to the following example code.
Java |
Copy Code |
---|---|
// Insert the range of cell worksheet.getRange("A3").insert(); // Insert the range of cells worksheet.getRange("A3:C10").insert(); |
In order to insert cell range in a worksheet while specifying the desired shift direction for the existing cells, refer to the following example code.
Java |
Copy Code |
---|---|
// Insert the range of cells from desired direction worksheet.getRange("A3:C10").insert(InsertShiftDirection.Down); worksheet.getRange("A3:C10").insert(InsertShiftDirection.Right); |
DsExcel Java allow you to delete a cell or a range of cells in the worksheets by calling the delete method of the IRange interface. To remove a cell or a range of cells, specify the cell range, for example B4 for a single cell or B4:C4 for a range of cells.
DsExcel Java provides the following different options to delete a cell or range of cells.
Method | Description |
---|---|
delete | This method automatically deletes a cell or the range of cells. |
delete(DeleteShiftDirection.Left) | This method deletes the range of cells and moves the existing range of cells to the left. |
delete(DeleteShiftDirection.Up) | This method delete the range of cells and move the existing range of cells in upward direction. |
In order to delete a single cell or a cell range in a worksheet, refer to the following example code.
Java |
Copy Code |
---|---|
// Delete the range of cell worksheet.getRange("A3").delete(); // Delete the range of cells worksheet.getRange("A3:C10").delete(); |
In order to delete a single cell or a range of cells in a worksheet while specifying the desired shift direction for the existing cells, refer to the following example code.
Java |
Copy Code |
---|---|
// Delete the range of cells from desired direction worksheet.getRange("A3:C10").delete(DeleteShiftDirection.Left); worksheet.getRange("A3:C10").delete(DeleteShiftDirection.Up); |