Delete Cells and shift

is there a way in aspose to delete (and/or Add) cells and shift remaining cells left or right or up and down?

Hi,

Thanks for considering Aspose.

Yes, you may delete or insert a range of cells and shift the data up, down, left, right or none for your need. You may use overloaded methods Cells.DeleteRange() and Cells.InsertRange() with ShiftType enum as their arguments. Possible members of the enumeration are:

Down Shift cells down.
Left Shift cells left.
None Do not shift cells.
Right Shift cells right.
Up Shift cells up.

May the following example with the template file (attached) provide help how to use them with shifting of the cells:

(Note: Kindly check the template file first before executing the code. In the template a range of cells (MyRange) is already created. In the example, the template range is obtained first, five rows are added at 3rd row index, a new range is created which copies the old range then the old range is deleted with shifting remaining data upwards )

Workbook workbook = new Workbook();

workbook.Open(@"d:\\test\bkRange.xls");

Worksheets worksheets = workbook.Worksheets;

Worksheet worksheet = workbook.Worksheets[0];

Range range1 = worksheets.GetRangeByName("MyRange");

worksheet.Cells.InsertRows(3,5, true);

Range range2 = worksheet.Cells.CreateRange("D4","K10");

range2.Name = "newrange";

range2.Copy(range1);

//Delete the previous range of cells with shifting all remaining data upwards.

worksheet.Cells.DeleteRange(10,3,16,10,ShiftType.Up);

workbook.Save("d:\\test\\tstbkRange.xls");

Thank you.

1 Like