2010-11-30 9 views
7

tengo el siguiente problema. Tengo que leer un archivo de Excel a través de la interoperabilidad COM. Soy nuevo en la programación con interoperabilidad COM.¿Cómo obtener Rango específico en Excel a través de Interop COM?

que buscar una cadena específica utilizando la siguiente:

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 quiero usar la foundRange como punto de partida para conseguir otro rango.

Algo como esto

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

no veo una manera de hacer esto. ¿Hay alguno?

Respuesta

25

Bien, después de dormir he encontrado la respuesta.

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]; 
Cuestiones relacionadas