How to get a specific range in Excel via COM Interop?

I have the following problem. I have to read the excel file through COM interop. I am new to programming using COM interoperability.

I am looking for a specific string using this:

this.sheet = (Excel.Worksheet)this.excelApp.Workbook.Sheets.Item[this.sheetname]; this.sheet.Activate(); Excel.Range firstRow = this.sheet.Range["A1", "XFD1"]; Excel.Range foundRange = firstRow.Find( this.StringISearch, Type.Missing, Type.Missing, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlNext, false, false, Type.Missing); 

No, I want to use the found Range as a starting point to get another range.

Something like that

 Excel.Range MyRange = this.sheet.Range[foundRange + 2 rows, + 1 column & lastRow]; 

I see no way to do this. There is one?

+7
c # excel range com-interop
source share
1 answer

Well, after some sleep, I found the answer.

  int startColumn = Header.Cells.Column; int startRow = header.Cells.Row + 1; Excel.Range startCell = this.sheet.Cells[startRow, startColumn]; int endColumn = startColumn + 1; int endRow = 65536; Excel.Range endCell = this.sheet.Cells[endRow, endColumn]; Excel.Range myRange = this.sheet.Range[startCell, endCell]; 
+25
source share

All Articles