Deleting a range of rows

I'm trying to write a line of code that will accomplish doing a select on Rows 45 through 55, then Delete the rows and let the rows below shift up. I want to delete the entire Row, not just selected columns.

I tried this:
sht.Range["45:55"].Clear(ExcelMoveDirection.MoveUp);

but it took "System.ArgumentException was unhandled by user code"
Message="Wrong range name format - alpha part "

Any ideas? TIA

3 Replies

CP Chella Pandian B Syncfusion Team November 15, 2006 09:42 PM UTC

Hi Chuck

I think this must help you.

// Where 45 is the first row. 1 is the column of 45 row. 55 is the last row and 10 is the last column in 55th row. It mean I have 10 columns in my excel sheet.

sheet.Range[45,1,55,10].Clear(ExcelMoveDirection.MoveUp);

Let me know if you have any other queries.

With regards,
Chella.


CH Chuck November 16, 2006 02:22 PM UTC

Thank you for assistance. That method does give me a way to select and clear a range of cells.

Unfortunately deleting a range of cells is not the same a deleting a range of rows. For one thing, it leaves the spreadsheet with the same last used row as before the clear operation, where deleting rows changes the last used row.

Is there a way of deleting either 1 or many entire rows? That is, without specifying columns too?

TIA again.


CP Chella Pandian B Syncfusion Team November 16, 2006 03:53 PM UTC

Hi Chuck

I have found you another solution.


// This will delete 10 rows from 45th row
for(int i=1;i<=10;i++)
{
sheet.DeleteRow(45);
}

I have even attached a sample too.

Sample:

DeleteRows.zip

With Regards,
Chella.

Loader.
Up arrow icon