Address

class pygsheets.Address(value, allow_non_single=False)[source]

Represents the address of a cell. This can also be unbound in an axes. So ‘A’ is also a valid address but this requires explict setting of param allow_non_single. Integer Indexes start from 1.

>>> a = Address('A2')
>>> a.label
A2
>>> a[0]
1
>>> a[1]
2
>>> a = Address((1, 2))
>>> a.label
A2
>>> a + (0,1)
<Address B2>
>>> a == (2, 2)
True
label

Label of the current address in A1 format.

row

Row of the address

col

Column of the address

index

Current Address in tuple format. Both axes starts at 1.

class pygsheets.GridRange(label=None, worksheet=None, start=None, end=None, worksheet_title=None, worksheet_id=None, propertiesjson=None)[source]

Represents a rectangular (can be unbounded) range of adresses on a sheet. All indexes are one-based and are closed, ie the start index and the end index is inclusive Missing indexes indicate the range is unbounded on that side.

A:B, A1:B3, 1:2 are all valid index, but A:1, 2:D are not

grange.start = (1, None) will make the range unbounded on column grange.indexes = ((None, None), (None, None)) will make the range completely unbounded, ie. whole sheet

Example:

>>> grange = GridRange(worksheet=wks, start='A1', end='D4')
>>> grange
<GridRange Sheet1!A1:D4>
>>> grange.start = 'A' # will remove bounding in rows
<GridRange Sheet1!A:D>
>>> grange.start = 'A1' # cannot add bounding at just start
<GridRange Sheet1!A:D>
>>> grange.indexes = ('A1', 'D4') # cannot add bounding at just start
<GridRange Sheet1!A1:D4>
>>> grange.end = (3, 5) # tuples will also work
<GridRange Sheet1!A1:C5>
>>> grange.end = (None, 5) # make unbounded on rows
<GridRange Sheet1!1:5>
>>> grange.end = (None, None) # make it unbounded on one index
<GridRange Sheet1!1:1>
>>> grange.start = None # make it unbounded on both indexes
<GridRange Sheet1>
>>> grange.start = 'A1' # make it unbounded on single index,now AZ100 is bottom right cell of worksheet
<GridRange Sheet1:A1:AZ100>

Reference: GridRange API docs

start

address of top left cell (index).

end

address of bottom right cell (index)

indexes

Indexes of this range as a tuple

label

Label in A1 notation format

worksheet_id

Id of woksheet this range belongs to

worksheet_title

Title of woksheet this range belongs to

set_worksheet(value)[source]

set the worksheet of this grid range.

to_json()[source]

Get json representation of this grid range.

set_json(namedjson)[source]

Apply a Gridrange json to this named range.

Parameters:namedjson – json object of the GridRange format

Reference: GridRange docs

get_bounded_indexes()[source]

get bounded indexes of this range based on worksheet size, if the indexes are unbounded

height

Height of this gridrange

width

Width of this gridrange