Aspose.cells- DeleteRow() and indices

Hey there,
Let’s say I’d like to delete rows 10 and 11 from an excel file.
doing this:
myWorksheet.Cells.DeleteRow(9);
myWorksheet.Cells.DeleteRow(10);
deletes lines 10 and 12 while doing

myWorksheet.Cells.DeleteRow(9);

myWorksheet.Cells.DeleteRow(9);
returns an error saying that the index is out of bounds.

To clarify things, the numbers 9 and 10 are just for the sake of the example. I don’t know the indices to delete up front so I can’t use DeleteRows()

Thanks in advance for your help.

Hi,

Thanks for pointing it out.

For .... myWorksheet.Cells.DeleteRow(9);
myWorksheet.Cells.DeleteRow(10);
deletes lines 10 and 12 while doing

Well, we follow the MS Excel standards. When the first line will run, the 10 rows will be deleted. Consequently, the 11th row becomes the 10 row and the 12 th row becomes the 11th row. So when the second line executes, it will originally remove the 12th row. Got it! I think you may test manually in MS Excel for confirmation.

For......myWorksheet.Cells.DeleteRow(9);
myWorksheet.Cells.DeleteRow(9);
returns an error saying that the index is out of bounds.

I don't find the problem, it actually deletes your desired rows i.e.., 10 and 11. Which version of Aspose.Cells you are using? Could you try the attached version (4.5.0.28). If you still find the error, kindly do post your template excel file here, we will check it soon.

And, alternatively, you may also try if it is feasible for you:

e.g..,

myWorksheet.Cells.DeleteRows(9,2);

Thank you.