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. First index correspond to the rows, second index corresponds to columns. Integer Indexes start from 1.

>>> a = Address('A2')
>>> a.index
(2, 1)
>>> a.label
'A2'
>>> a[0]
2
>>> a[1]
1
>>> a = Address((1, 4))
>>> a.index
(1, 4)
>>> a.label
D1
>>> b = a + (3,0)
>>> b
<Address D4>
>>> b == (4, 4)
True
>>> column_a = Address((None, 1), True)
>>> column_a
<Address A>
>>> row_2 = Address('2', True)
>>> row_2
<Address 2>
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>
>>> 'A1' in grange
True
>>> (100,100) in grange
False
>>> for address in grange:
>>>     print(address)
Address((1,1))
Address((1,2))
...

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

static create(data, wks=None)[source]
create a Gridrange from various type of data
Parameters:
  • data – can be string in A format,tuple or list, dict in GridRange format, GridRange object
  • wks – worksheet to link to (optional)
Returns:

GridRange object

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