Spread.Services Documentation
Insert And Delete Cell Ranges
Spread.Services Documentation > Developer's Guide > Customize User Interaction > Manage Worksheet > Range Operations > Insert And Delete Cell Ranges

Spread.Services enables you to insert and delete a cell or a range of cells in order to help customization of worksheets as per your requirements.

Insert cell range

Spread.Services allows you to add a cell or a range of cells in a worksheets by calling the Insert method of IRange. 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.

Spread.Services provides following different options to insert a cell or a range of cells.

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 insert the range of cells and shifts the existing range of cells to the right.

Refer to the following example code to see how you can insert a single cell and a cell range in the worksheet.

C#
Copy Code
//Insert the range of cell
worksheet.Range["A3"].Insert();

// Insert the range of cells
worksheet.Range["A3:A5"].Insert();

Refer to the following example code to see how you can insert cell range in a worksheet while specifying a direction to shift the existing cells in required direction.

C#
Copy Code
//Insert the range of cells in desired direction
worksheet.Range["A3:B10"].Insert(InsertShiftDirection.Down);
worksheet.Range["A5:C5"].Insert(InsertShiftDirection.Right);

Delete cell range

Spread.Services allow you to delete a cell or a range of cells in the worksheets by calling Delete method of IRange. 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.

Spread.Services provide 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.

Refer to the following example code to see how you can delete single cell or a cell range in a worksheet.

C#
Copy Code
//Delete the range of cell
worksheet.Range["B4"].Delete();

// Delete the range of cells
worksheet.Range["B4:C4"].Delete();

Refer to the following example code to see how you can delete a single cell or a range of cells in a worksheet while specifying a direction to shift the existing cells in required direction.

C#
Copy Code
//Delete the range of cells from desired direction
worksheet.Range["B3:C8"].Delete(DeleteShiftDirection.Left);
worksheet.Range["B5:D5"].Delete(DeleteShiftDirection.Up);
See Also