Cell

class pygsheets.Cell(pos, val='', worksheet=None, cell_data=None)[source]

Represents a single cell of a sheet.

Each cell is either a simple local value or directly linked to a specific cell of a sheet. When linked any changes to the cell will update the Worksheet immediately.

Parameters:
  • pos – Address of the cell as coordinate tuple or label.
  • val – Value stored inside of the cell.
  • worksheet – Worksheet this cell belongs to.
  • cell_data – This cells data stored in json, with the same structure as cellData of the Google Sheets API v4.
borders = None

Border Properties as dictionary. Reference: api object.

parse_value = None

Determines how values are interpreted by Google Sheets (True: USER_ENTERED; False: RAW).

Reference: sheets api

row

Row number of the cell.

col

Column number of the cell.

label

This cells label (e.g. ‘A1’).

value

This cells formatted value.

value_unformatted

Unformatted value of this cell.

formula

Get/Set this cells formula if any.

horizontal_alignment

Horizontal alignment of the value in this cell. possible vlaues: :class:`cell <HorizontalAlignment>

vertical_alignment

Vertical alignment of the value in this cell. possible vlaues: :class:`cell <VerticalAlignment>

wrap_strategy

How to wrap text in this cell. Possible wrap strategies: ‘OVERFLOW_CELL’, ‘LEGACY_WRAP’, ‘CLIP’, ‘WRAP’. Reference: api docs

note

Get/Set note of this cell.

color

Get/Set background color of this cell as a tuple (red, green, blue, alpha).

simple

Simple cells only fetch the value itself. Set to false to fetch all cell properties.

set_text_format(attribute, value)[source]

Set a text format property of this cell.

Each format property must be set individually. Any format property which is not set will be considered unspecified.

Attribute:
  • foregroundColor: Sets the texts color. (tuple as (red, green, blue, alpha))
  • fontFamily: Sets the texts font. (string)
  • fontSize: Sets the text size. (integer)
  • bold: Set/remove bold format. (boolean)
  • italic: Set/remove italic format. (boolean)
  • strikethrough: Set/remove strike through format. (boolean)
  • underline: Set/remove underline format. (boolean)

Reference: api docs

Parameters:
  • attribute – The format property to set.
  • value – The value the format property should be set to.
Returns:

cell

set_number_format(format_type, pattern='')[source]

Set number format of this cell.

Reference: api docs

Parameters:
  • format_type – The type of the number format. Should be of type FormatType.
  • pattern – Pattern string used for formatting. If not set, a default pattern will be used. See reference for supported patterns.
Returns:

cell

set_text_rotation(attribute, value)[source]

The rotation applied to text in this cell.

Can be defined as “angle” or as “vertical”. May not define both!

angle:

[number] The angle between the standard orientation and the desired orientation. Measured in degrees. Valid values are between -90 and 90. Positive angles are angled upwards, negative are angled downwards.

Note: For LTR text direction positive angles are in the counterclockwise direction, whereas for RTL they are in the clockwise direction.

vertical:
[boolean] If true, text reads top to bottom, but the orientation of individual characters is unchanged.

Reference: api_docs <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#textrotation>

Parameters:
  • attribute – “angle” or “vertical”
  • value – Corresponding value for the attribute. angle in (-90,90) for ‘angle’, boolean for ‘vertical’
Returns:

cell

set_horizontal_alignment(value)[source]

Set horizondal alignemnt of text in the cell

Parameters:value – Horizondal alignment value, instance of cell
Returns:cell
set_vertical_alignment(value)[source]

Set vertical alignemnt of text in the cell

Parameters:value – Vertical alignment value, instance of cell
Returns:cell
set_value(value)[source]
Set value of the cell
:param value: value to be set
return:cell

Unlink this cell from its worksheet.

Unlinked cells will no longer automatically update the sheet when changed. Use update or link to update the sheet.

Link cell with the specified worksheet.

Linked cells will synchronize any changes with the sheet as they happen.

Parameters:
  • worksheet – The worksheet to link to. Can be None if the cell was linked to a worksheet previously.
  • update – Update the cell immediately after linking if the cell has changed
Returns:

cell

neighbour(position)[source]

Get a neighbouring cell of this cell.

Parameters:position – This may be a string ‘right’, ‘left’, ‘top’, ‘bottom’ or a tuple of relative positions (e.g. (1, 2) will return a cell one below and two to the right).
Returns:neighbouring cell
fetch(keep_simple=False)[source]

Update the value in this cell from the linked worksheet.

refresh()[source]

Refresh the value and properties in this cell from the linked worksheet. Same as fetch.

update(force=False, get_request=False, worksheet_id=None)[source]

Update the cell of the linked sheet or the worksheet given as parameter.

Parameters:
  • force – Force an update from the sheet, even if it is unlinked.
  • get_request – Return the request object instead of sending the request directly.
  • worksheet_id – Needed if the cell is not linked otherwise the cells worksheet is used.
get_json()[source]

Returns the cell as a dictionary structured like the Google Sheets API v4.

set_json(cell_data)[source]

Reads a json-dictionary returned by the Google Sheets API v4 and initialize all the properties from it.

Parameters:cell_data – The cells data.