Cut and Paste Ranges

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-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CountNumberOfCells.class) + "Worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCells().get(0, 2).setValue(1);
worksheet.getCells().get(1, 2).setValue(2);
worksheet.getCells().get(2, 2).setValue(3);
worksheet.getCells().get(2, 3).setValue(4);
worksheet.getCells().createRange(0, 2, 3, 1).setName("NamedRange");
Range cut = worksheet.getCells().createRange("C:C");
worksheet.getCells().insertCutCells(cut, 0, 1, ShiftType.RIGHT);
workbook.save(dataDir + "CutAndPasteCells.xlsx");