How to get specific Range in Excel through COM Interop?

i have the following problem. I have to read an excel file through COM interop. I am new to programming with COM interop.

I search 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 foundRange as a starting point to get another range.

Something like this

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

I don't see a way to do this. Is there one?

Answers


Okay, after some sleep i have 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];

Need Your Help

Facebook PHP web app doesn't work when accessed from account other than app administrator

php facebook facebook-fql facebook-php-sdk

I have a very simple PHP app that retrieves a users & friends RSVPd events using FQL. It is using the latest PHP SKD. The code works perfectly when I am logged in and authenticated as the account

Reporting services print to pdf (not export) fails?

reporting-services

When you hit the print icon in reporting services and choose a print to pdf service (such as Adobe) and error occurs and it never prints.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.