Cut and Paste Range

Cut and Paste Cells

Aspose.Cells provides you with the ability to cut and paste cells within a worksheet by using the InsertCutCells method of the Cells collection. The InsertCutCells accepts the following parameters.

  • Range: The range of cells to be cut.
  • Row Index: The index of the row to insert cells.
  • Column Index: The index of the column to insert cells.
  • ShiftType: The shift direction of the columns.

The following example shows how to cut and paste cells within a worksheet.

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string outDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells[0, 2].Value = 1;
worksheet.Cells[1, 2].Value = 2;
worksheet.Cells[2, 2].Value = 3;
worksheet.Cells[2, 3].Value = 4;
worksheet.Cells.CreateRange(0, 2, 3, 1).Name = "NamedRange";
Range cut = worksheet.Cells.CreateRange("C:C");
worksheet.Cells.InsertCutCells(cut, 0, 1, ShiftType.Right);
workbook.Save(outDir + "CutAndPasteCells.xlsx");