Adding rows to ranges in Excel worksheet in .NET

Hi amjad,

I already have some ranges defind in my excel.

I want to add new rows in that ranges and shift the old ranges after row addition.

E.g I have 2 rows in the one range. Then I add 3 columns. So result will be range of 5 rows with the same name.

How to achieve this ?

Thanks

Shrikant

Hi,

Well, in Ms Excel when you add rows, the ranges are adjusted accordingly with the data, so you do not need to do anything, just add rows/columns or range by using methods like, Cells.InsertRow, InsertRows, InsertColumns, InsertColumn, InsertRange or AddRange, the ranges are adjusted automatically when you save the file and open it into Ms Excel.
If you find any issue, kindly give us your template file and sample runnable code to reproduce the issue on our end. We will check it soon.

See a sample code for reference:

Sample code:

Worksheet sheet1 = wb.Worksheets[0];

CellArea cellarea = new CellArea();

cellarea.StartRow = 15;

cellarea.StartColumn = 0;

cellarea.EndRow = 20;

cellarea.EndColumn = 5;

sheet1.Cells.InsertRange(cellarea, 0, ShiftType.Down, true);

wb.Save(@"e:\test2\myoutputcheck_1.xlsx");

Thank you.