Accessing Ranges
We’ve been calling the
Value
and Formula methods
without really knowing what they refer to. They are methods of an
object called a Range
, which refers to a range of
cells. You can use Ranges to get hold of regions
of a spreadsheet in several ways:
>>> myRange1 = xlSheet.Cells(4,1) # one-cell range
>>> myRange2 = xlSheet.Range("B5:C10") # excel notation
>>> myRange3 = xlSheet.Range(xlSheet.Cells(2,2), xlSheet.Cells(3,8))
>>>A sheet has a Range()
method that returns a
Range object. The Range method
can accept the usual Excel notation or a pair of one-cell
Range objects defining the top left and bottom
right. You can even perform intersections and unions to build
nonrectangular ranges. Once you have a Range
object, as mentioned earlier, you have 84 methods and 72 properties
to play with. These cover all the formatting options including data.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access