Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get an Excel range using row and column numbers in VSTO / C#?

Tags:

c#

excel

vsto

I think the question sums it up. Given two integers for row and column or four integers for row and column for the two corners of a range, how do I get a range object for that range.

like image 913
Dan Crowther Avatar asked Feb 25 '10 10:02

Dan Crowther


People also ask

How do you create a range in Excel?

Press F5 or CTRL+G to launch the Go To dialog. In the Go to list, click the name of the cell or range that you want to select, or type the cell reference in the Reference box, then press OK. For example, in the Reference box, type B3 to select that cell, or type B1:B3 to select a range of cells.

What is Excel range in C#?

Excel. Range that contains a single cell, an entire column, an entire row, or it can be a string that names a single cell in the language of the application.

What is an Excel range?

Package: excel. Range represents a set of one or more contiguous cells such as a cell, a row, a column, or a block of cells.


1 Answers

Where the range is multiple cells:

Excel.Worksheet sheet = workbook.ActiveSheet; Excel.Range rng = (Excel.Range) sheet.get_Range(sheet.Cells[1, 1], sheet.Cells[3,3]); 

Where range is one cell:

Excel.Worksheet sheet = workbook.ActiveSheet; Excel.Range rng = (Excel.Range) sheet.Cells[1, 1]; 
like image 154
burnside Avatar answered Sep 21 '22 00:09

burnside