gspread-formatting


Namegspread-formatting JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/robin900/gspread-formatting
SummaryComplete Google Sheets formatting support for gspread worksheets
upload_time2024-06-12 18:16:23
maintainerNone
docs_urlNone
authorRobin Thomas
requires_pythonNone
licenseMIT
keywords spreadsheets google-spreadsheets formatting cell-format
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            gspread-formatting
------------------

.. image:: https://badge.fury.io/py/gspread-formatting.svg
    :target: https://badge.fury.io/py/gspread-formatting

.. image:: https://img.shields.io/pypi/dm/gspread-formatting.svg
    :target: https://pypi.org/project/gspread-formatting

This package provides complete cell formatting for Google spreadsheets
using the popular ``gspread`` package, along with a few related features such as setting
"frozen" rows and columns in a worksheet. Both basic and conditional formatting operations
are supported.

The package also offers graceful formatting of Google spreadsheets using a Pandas DataFrame.
See the section below for usage and details.

Usage
~~~~~

Basic formatting of a range of cells in a worksheet is offered by the ``format_cell_range`` function. 
All basic formatting components of the v4 Sheets API's ``CellFormat`` are present as classes 
in the ``gspread_formatting`` module, available both by ``InitialCaps`` names and ``camelCase`` names: 
for example, the background color class is ``BackgroundColor`` but is also available as 
``backgroundColor``, while the color class is ``Color`` but available also as ``color``. 
Attributes of formatting components are best specified as keyword arguments using ``camelCase`` 
naming, e.g. ``backgroundColor=...``. Complex formats may be composed easily, by nesting the calls to the classes.  

See `the CellFormat page of the Sheets API documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellFormat>`_
to learn more about each formatting component.::

    from gspread_formatting import *

    fmt = cellFormat(
        backgroundColor=color(1, 0.9, 0.9),
        textFormat=textFormat(bold=True, foregroundColor=color(1, 0, 1)),
        horizontalAlignment='CENTER'
        )

    format_cell_range(worksheet, 'A1:J1', fmt)

The ``format_cell_ranges`` function allows for formatting multiple ranges with corresponding formats,
all in one function call and Sheets API operation::

    fmt = cellFormat(
        backgroundColor=color(1, 0.9, 0.9),
        textFormat=textFormat(bold=True, foregroundColor=color(1, 0, 1)),
        horizontalAlignment='CENTER'
        )

    fmt2 = cellFormat(
        backgroundColor=color(0.9, 0.9, 0.9),
        horizontalAlignment='RIGHT'
        )

    format_cell_ranges(worksheet, [('A1:J1', fmt), ('K1:K200', fmt2)])

Specifying Cell Ranges
~~~~~~~~~~~~~~~~~~~~~~

The `format_cell_range` function and friends allow a string to specify a cell range using the "A1" convention
to name a column-and-row cell address with column letter and row number; in addition, one may specify
an entire column or column range with unbounded rows, or an entire row or row range with unbounded columns,
or a combination thereof. Here are some examples::

    A1     # column A row 1
    A1:A2  # column A, rows 1-2
    A      # entire column A, rows unbounded
    A:A    # entire column A, rows unbounded
    A:C    # entire columns A through C
    A:B100 # columns A and B, unbounded start through row 100
    A100:B # columns A and B, from row 100 with unbounded end 
    1:3    # entire rows 1 through 3, all columns
    1      # entire row 1


Retrieving, Comparing, and Composing CellFormats
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A Google spreadsheet's own default format, as a CellFormat object, is available via ``get_default_format(spreadsheet)``.
``get_effective_format(worksheet, label)`` and ``get_user_entered_format(worksheet, label)`` also will return
for any provided cell label either a CellFormat object (if any formatting is present) or None.

``CellFormat`` objects are comparable with ``==`` and ``!=``, and are mutable at all times; 
they can be safely copied with Python's ``copy.deepcopy`` function. ``CellFormat`` objects can be combined
into a new ``CellFormat`` object using the ``add`` method (or ``+`` operator). ``CellFormat`` objects also offer 
``difference`` and ``intersection`` methods, as well as the corresponding
operators ``-`` (for difference) and ``&`` (for intersection).::

    >>> default_format = CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True))
    >>> user_format = CellFormat(textFormat=textFormat(italic=True))
    >>> effective_format = default_format + user_format
    >>> effective_format
    CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True, italic=True))
    >>> effective_format - user_format 
    CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True))
    >>> effective_format - user_format == default_format
    True

Frozen Rows and Columns
~~~~~~~~~~~~~~~~~~~~~~~

The following functions get or set "frozen" row or column counts for a worksheet::

    get_frozen_row_count(worksheet)
    get_frozen_column_count(worksheet)
    set_frozen(worksheet, rows=1)
    set_frozen(worksheet, cols=1)
    set_frozen(worksheet, rows=1, cols=0)

Setting Row Heights and Column Widths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following functions set the height (in pixels) of rows or width (in pixels) of columns::

    set_row_height(worksheet, 1, 42)
    set_row_height(worksheet, '1:100', 42)
    set_row_heights(worksheet, [ ('1:100', 42), ('101:', 22) ])
    set_column_width(worksheet, 'A', 190)
    set_column_width(worksheet, 'A:D', 100)
    set_column_widths(worksheet, [ ('A', 200), ('B:', 100) ])

Working with Right-to-Left Language Alphabets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following example shows the functions to get or set the `rightToLeft` property of a worksheet::

    get_right_to_left(worksheet)
    set_right_to_left(worksheet, True)

Also note the presence of the argument `textDirection=` to `CellFormat`: set it to `'RIGHT_TO_LEFT'`
in order to use right-to-left text in an individual cell in an otherwise left-to-right worksheet.

Getting and Setting Data Validation Rules for Cells and Cell Ranges
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following functions get or set the "data validation rule" for a cell or cell range::

    get_data_validation_rule(worksheet, label)
    set_data_validation_for_cell_range(worksheet, range, rule)
    set_data_validation_for_cell_ranges(worksheet, ranges)

The full functionality of data validation rules is supported: all of ``BooleanCondition``. 
See `the API documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#DataValidationRule>`_
for more information. Here's a short example::

    validation_rule = DataValidationRule(
        BooleanCondition('ONE_OF_LIST', ['1', '2', '3', '4']),
        showCustomUi=True
    )
    set_data_validation_for_cell_range(worksheet, 'A2:D2', validation_rule)
    # data validation for A2
    eff_rule = get_data_validation_rule(worksheet, 'A2')
    eff_rule.condition.type
    >>> 'ONE_OF_LIST'
    eff_rule.showCustomUi
    >>> True
    # No data validation for A1
    eff_rule = get_data_validation_rule(worksheet, 'A1')
    eff_rule
    >>> None
    # Clear data validation rule by using None
    set_data_validation_for_cell_range(worksheet, 'A2', None)
    eff_rule = get_data_validation_rule(worksheet, 'A2')
    eff_rule
    >>> None


Formatting a Worksheet Using a Pandas DataFrame
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are using Pandas DataFrames to provide data to a Google spreadsheet -- using perhaps
the ``gspread-dataframe`` package `available on PyPI <https://pypi.org/project/gspread-dataframe/>`_ --
the ``format_with_dataframe`` function in ``gspread_formatting.dataframe`` allows you to use that same 
DataFrame object and specify formatting for a worksheet. There is a ``DEFAULT_FORMATTER`` in the module,
which will be used if no formatter object is provided to ``format_with_dataframe``::

    from gspread_formatting.dataframe import format_with_dataframe, BasicFormatter
    from gspread_formatting import Color

    # uses DEFAULT_FORMATTER
    format_with_dataframe(worksheet, dataframe, include_index=True, include_column_header=True)

    formatter = BasicFormatter(
        header_background_color=Color(0,0,0), 
        header_text_color=Color(1,1,1),
        decimal_format='#,##0.00'
    )

    format_with_dataframe(worksheet, dataframe, formatter, include_index=False, include_column_header=True)


Batch Mode for API Call Efficiency
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This package offers a "batch updater" object, with methods having the same names and parameters as the 
formatting functions in the package. The batch updater will gather all formatting requests generated 
by calling these methods, and send them all to the Google Sheets API in a single ``batchUpdate`` 
request when ``.execute()`` is invoked on the batch updater. Alternately, you can use the batch updater
as a context manager in a ``with:`` block, which will automate the call to ``.execute()``::

    from gspread_formatting import batch_updater

    sheet = some_gspread_worksheet

    # Option 1: call execute() directly
    batch = batch_updater(sheet.spreadsheet)
    batch.format_cell_range(sheet, '1', cellFormat(textFormat=textFormat(bold=True)))
    batch.set_row_height(sheet, '1', 32)
    batch.execute()

    # Option 2: use with: block
    with batch_updater(sheet.spreadsheet) as batch:
        batch.format_cell_range(sheet, '1', cellFormat(textFormat=textFormat(bold=True)))
        batch.set_row_height(sheet, '1', 32)


Conditional Format Rules
~~~~~~~~~~~~~~~~~~~~~~~~

A conditional format rule allows you to specify a cell format that (additively) applies to cells in certain ranges
only when the value of the cell meets a certain condition. 
The `ConditionalFormatRule documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#ConditionalFormatRule>`_ for the Sheets API describes the two kinds of rules allowed:
a ``BooleanRule`` in which the `CellFormat` is applied to the cell if the value meets the specified boolean
condition; or a ``GradientRule`` in which the ``Color`` or ``ColorStyle`` of the cell varies depending on the numeric
value of the cell or cells. 

You can specify multiple rules for each worksheet present in a Google spreadsheet. To add or remove rules,
use the ``get_conditional_format_rules(worksheet)`` function, which returns a list-like object which you can
modify as you would modify a list, and then call ``.save()`` to store the rule changes you've made.

Here is an example that applies bold text and a bright red color to cells in column A if the cell value
is numeric and greater than 100::

    from gspread_formatting import *

    worksheet = some_spreadsheet.worksheet('My Worksheet')

    rule = ConditionalFormatRule(
        ranges=[GridRange.from_a1_range('A1:A2000', worksheet)],
        booleanRule=BooleanRule(
            condition=BooleanCondition('NUMBER_GREATER', ['100']), 
            format=CellFormat(textFormat=textFormat(bold=True), backgroundColor=Color(1,0,0))
        )
    )

    rules = get_conditional_format_rules(worksheet)
    rules.append(rule)
    rules.save()

    # or, to replace any existing rules with just your single rule:
    rules.clear()
    rules.append(rule)
    rules.save()

An important note: A ``ConditionalFormatRule`` is, like all other objects provided by this package,
mutable in all of its fields. Mutating a ``ConditionalFormatRule`` object in place will not automatically
store the changes via the Sheets API; but calling `.save()` on the list-like rules object will store
the mutated rule as expected.


Installation
------------

Requirements
~~~~~~~~~~~~

* Python 2.7, 3.x; PyPy and PyPy3
* gspread >= 3.0.0

From PyPI
~~~~~~~~~

::

    pip install gspread-formatting

From GitHub
~~~~~~~~~~~

::

    git clone https://github.com/robin900/gspread-formatting.git
    cd gspread-formatting
    python setup.py install

Development and Testing
-----------------------

Install packages listed in ``requirements-dev.txt``. To run the test suite
in ``test.py`` you will need to:

* Authorize as the Google account you wish to use as a test, and download
  a JSON file containing the credentials. Name the file ``creds.json``
  and locate it in the top-level folder of the repository.
* Set up a ``tests.config`` file using the ``tests.config.example`` file as a template.
  Specify the ID of a spreadsheet that the Google account you are using
  can access with write privileges.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/robin900/gspread-formatting",
    "name": "gspread-formatting",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "spreadsheets, google-spreadsheets, formatting, cell-format",
    "author": "Robin Thomas",
    "author_email": "rthomas900@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/44/b6/811417edee4a1c7705c4ae54ea6fce749f15474b6c6deddb0f11ec303838/gspread-formatting-1.2.0.tar.gz",
    "platform": null,
    "description": "gspread-formatting\n------------------\n\n.. image:: https://badge.fury.io/py/gspread-formatting.svg\n    :target: https://badge.fury.io/py/gspread-formatting\n\n.. image:: https://img.shields.io/pypi/dm/gspread-formatting.svg\n    :target: https://pypi.org/project/gspread-formatting\n\nThis package provides complete cell formatting for Google spreadsheets\nusing the popular ``gspread`` package, along with a few related features such as setting\n\"frozen\" rows and columns in a worksheet. Both basic and conditional formatting operations\nare supported.\n\nThe package also offers graceful formatting of Google spreadsheets using a Pandas DataFrame.\nSee the section below for usage and details.\n\nUsage\n~~~~~\n\nBasic formatting of a range of cells in a worksheet is offered by the ``format_cell_range`` function. \nAll basic formatting components of the v4 Sheets API's ``CellFormat`` are present as classes \nin the ``gspread_formatting`` module, available both by ``InitialCaps`` names and ``camelCase`` names: \nfor example, the background color class is ``BackgroundColor`` but is also available as \n``backgroundColor``, while the color class is ``Color`` but available also as ``color``. \nAttributes of formatting components are best specified as keyword arguments using ``camelCase`` \nnaming, e.g. ``backgroundColor=...``. Complex formats may be composed easily, by nesting the calls to the classes.  \n\nSee `the CellFormat page of the Sheets API documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellFormat>`_\nto learn more about each formatting component.::\n\n    from gspread_formatting import *\n\n    fmt = cellFormat(\n        backgroundColor=color(1, 0.9, 0.9),\n        textFormat=textFormat(bold=True, foregroundColor=color(1, 0, 1)),\n        horizontalAlignment='CENTER'\n        )\n\n    format_cell_range(worksheet, 'A1:J1', fmt)\n\nThe ``format_cell_ranges`` function allows for formatting multiple ranges with corresponding formats,\nall in one function call and Sheets API operation::\n\n    fmt = cellFormat(\n        backgroundColor=color(1, 0.9, 0.9),\n        textFormat=textFormat(bold=True, foregroundColor=color(1, 0, 1)),\n        horizontalAlignment='CENTER'\n        )\n\n    fmt2 = cellFormat(\n        backgroundColor=color(0.9, 0.9, 0.9),\n        horizontalAlignment='RIGHT'\n        )\n\n    format_cell_ranges(worksheet, [('A1:J1', fmt), ('K1:K200', fmt2)])\n\nSpecifying Cell Ranges\n~~~~~~~~~~~~~~~~~~~~~~\n\nThe `format_cell_range` function and friends allow a string to specify a cell range using the \"A1\" convention\nto name a column-and-row cell address with column letter and row number; in addition, one may specify\nan entire column or column range with unbounded rows, or an entire row or row range with unbounded columns,\nor a combination thereof. Here are some examples::\n\n    A1     # column A row 1\n    A1:A2  # column A, rows 1-2\n    A      # entire column A, rows unbounded\n    A:A    # entire column A, rows unbounded\n    A:C    # entire columns A through C\n    A:B100 # columns A and B, unbounded start through row 100\n    A100:B # columns A and B, from row 100 with unbounded end \n    1:3    # entire rows 1 through 3, all columns\n    1      # entire row 1\n\n\nRetrieving, Comparing, and Composing CellFormats\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nA Google spreadsheet's own default format, as a CellFormat object, is available via ``get_default_format(spreadsheet)``.\n``get_effective_format(worksheet, label)`` and ``get_user_entered_format(worksheet, label)`` also will return\nfor any provided cell label either a CellFormat object (if any formatting is present) or None.\n\n``CellFormat`` objects are comparable with ``==`` and ``!=``, and are mutable at all times; \nthey can be safely copied with Python's ``copy.deepcopy`` function. ``CellFormat`` objects can be combined\ninto a new ``CellFormat`` object using the ``add`` method (or ``+`` operator). ``CellFormat`` objects also offer \n``difference`` and ``intersection`` methods, as well as the corresponding\noperators ``-`` (for difference) and ``&`` (for intersection).::\n\n    >>> default_format = CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True))\n    >>> user_format = CellFormat(textFormat=textFormat(italic=True))\n    >>> effective_format = default_format + user_format\n    >>> effective_format\n    CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True, italic=True))\n    >>> effective_format - user_format \n    CellFormat(backgroundColor=color(1,1,1), textFormat=textFormat(bold=True))\n    >>> effective_format - user_format == default_format\n    True\n\nFrozen Rows and Columns\n~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following functions get or set \"frozen\" row or column counts for a worksheet::\n\n    get_frozen_row_count(worksheet)\n    get_frozen_column_count(worksheet)\n    set_frozen(worksheet, rows=1)\n    set_frozen(worksheet, cols=1)\n    set_frozen(worksheet, rows=1, cols=0)\n\nSetting Row Heights and Column Widths\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following functions set the height (in pixels) of rows or width (in pixels) of columns::\n\n    set_row_height(worksheet, 1, 42)\n    set_row_height(worksheet, '1:100', 42)\n    set_row_heights(worksheet, [ ('1:100', 42), ('101:', 22) ])\n    set_column_width(worksheet, 'A', 190)\n    set_column_width(worksheet, 'A:D', 100)\n    set_column_widths(worksheet, [ ('A', 200), ('B:', 100) ])\n\nWorking with Right-to-Left Language Alphabets\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following example shows the functions to get or set the `rightToLeft` property of a worksheet::\n\n    get_right_to_left(worksheet)\n    set_right_to_left(worksheet, True)\n\nAlso note the presence of the argument `textDirection=` to `CellFormat`: set it to `'RIGHT_TO_LEFT'`\nin order to use right-to-left text in an individual cell in an otherwise left-to-right worksheet.\n\nGetting and Setting Data Validation Rules for Cells and Cell Ranges\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following functions get or set the \"data validation rule\" for a cell or cell range::\n\n    get_data_validation_rule(worksheet, label)\n    set_data_validation_for_cell_range(worksheet, range, rule)\n    set_data_validation_for_cell_ranges(worksheet, ranges)\n\nThe full functionality of data validation rules is supported: all of ``BooleanCondition``. \nSee `the API documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#DataValidationRule>`_\nfor more information. Here's a short example::\n\n    validation_rule = DataValidationRule(\n        BooleanCondition('ONE_OF_LIST', ['1', '2', '3', '4']),\n        showCustomUi=True\n    )\n    set_data_validation_for_cell_range(worksheet, 'A2:D2', validation_rule)\n    # data validation for A2\n    eff_rule = get_data_validation_rule(worksheet, 'A2')\n    eff_rule.condition.type\n    >>> 'ONE_OF_LIST'\n    eff_rule.showCustomUi\n    >>> True\n    # No data validation for A1\n    eff_rule = get_data_validation_rule(worksheet, 'A1')\n    eff_rule\n    >>> None\n    # Clear data validation rule by using None\n    set_data_validation_for_cell_range(worksheet, 'A2', None)\n    eff_rule = get_data_validation_rule(worksheet, 'A2')\n    eff_rule\n    >>> None\n\n\nFormatting a Worksheet Using a Pandas DataFrame\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you are using Pandas DataFrames to provide data to a Google spreadsheet -- using perhaps\nthe ``gspread-dataframe`` package `available on PyPI <https://pypi.org/project/gspread-dataframe/>`_ --\nthe ``format_with_dataframe`` function in ``gspread_formatting.dataframe`` allows you to use that same \nDataFrame object and specify formatting for a worksheet. There is a ``DEFAULT_FORMATTER`` in the module,\nwhich will be used if no formatter object is provided to ``format_with_dataframe``::\n\n    from gspread_formatting.dataframe import format_with_dataframe, BasicFormatter\n    from gspread_formatting import Color\n\n    # uses DEFAULT_FORMATTER\n    format_with_dataframe(worksheet, dataframe, include_index=True, include_column_header=True)\n\n    formatter = BasicFormatter(\n        header_background_color=Color(0,0,0), \n        header_text_color=Color(1,1,1),\n        decimal_format='#,##0.00'\n    )\n\n    format_with_dataframe(worksheet, dataframe, formatter, include_index=False, include_column_header=True)\n\n\nBatch Mode for API Call Efficiency\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis package offers a \"batch updater\" object, with methods having the same names and parameters as the \nformatting functions in the package. The batch updater will gather all formatting requests generated \nby calling these methods, and send them all to the Google Sheets API in a single ``batchUpdate`` \nrequest when ``.execute()`` is invoked on the batch updater. Alternately, you can use the batch updater\nas a context manager in a ``with:`` block, which will automate the call to ``.execute()``::\n\n    from gspread_formatting import batch_updater\n\n    sheet = some_gspread_worksheet\n\n    # Option 1: call execute() directly\n    batch = batch_updater(sheet.spreadsheet)\n    batch.format_cell_range(sheet, '1', cellFormat(textFormat=textFormat(bold=True)))\n    batch.set_row_height(sheet, '1', 32)\n    batch.execute()\n\n    # Option 2: use with: block\n    with batch_updater(sheet.spreadsheet) as batch:\n        batch.format_cell_range(sheet, '1', cellFormat(textFormat=textFormat(bold=True)))\n        batch.set_row_height(sheet, '1', 32)\n\n\nConditional Format Rules\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nA conditional format rule allows you to specify a cell format that (additively) applies to cells in certain ranges\nonly when the value of the cell meets a certain condition. \nThe `ConditionalFormatRule documentation <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#ConditionalFormatRule>`_ for the Sheets API describes the two kinds of rules allowed:\na ``BooleanRule`` in which the `CellFormat` is applied to the cell if the value meets the specified boolean\ncondition; or a ``GradientRule`` in which the ``Color`` or ``ColorStyle`` of the cell varies depending on the numeric\nvalue of the cell or cells. \n\nYou can specify multiple rules for each worksheet present in a Google spreadsheet. To add or remove rules,\nuse the ``get_conditional_format_rules(worksheet)`` function, which returns a list-like object which you can\nmodify as you would modify a list, and then call ``.save()`` to store the rule changes you've made.\n\nHere is an example that applies bold text and a bright red color to cells in column A if the cell value\nis numeric and greater than 100::\n\n    from gspread_formatting import *\n\n    worksheet = some_spreadsheet.worksheet('My Worksheet')\n\n    rule = ConditionalFormatRule(\n        ranges=[GridRange.from_a1_range('A1:A2000', worksheet)],\n        booleanRule=BooleanRule(\n            condition=BooleanCondition('NUMBER_GREATER', ['100']), \n            format=CellFormat(textFormat=textFormat(bold=True), backgroundColor=Color(1,0,0))\n        )\n    )\n\n    rules = get_conditional_format_rules(worksheet)\n    rules.append(rule)\n    rules.save()\n\n    # or, to replace any existing rules with just your single rule:\n    rules.clear()\n    rules.append(rule)\n    rules.save()\n\nAn important note: A ``ConditionalFormatRule`` is, like all other objects provided by this package,\nmutable in all of its fields. Mutating a ``ConditionalFormatRule`` object in place will not automatically\nstore the changes via the Sheets API; but calling `.save()` on the list-like rules object will store\nthe mutated rule as expected.\n\n\nInstallation\n------------\n\nRequirements\n~~~~~~~~~~~~\n\n* Python 2.7, 3.x; PyPy and PyPy3\n* gspread >= 3.0.0\n\nFrom PyPI\n~~~~~~~~~\n\n::\n\n    pip install gspread-formatting\n\nFrom GitHub\n~~~~~~~~~~~\n\n::\n\n    git clone https://github.com/robin900/gspread-formatting.git\n    cd gspread-formatting\n    python setup.py install\n\nDevelopment and Testing\n-----------------------\n\nInstall packages listed in ``requirements-dev.txt``. To run the test suite\nin ``test.py`` you will need to:\n\n* Authorize as the Google account you wish to use as a test, and download\n  a JSON file containing the credentials. Name the file ``creds.json``\n  and locate it in the top-level folder of the repository.\n* Set up a ``tests.config`` file using the ``tests.config.example`` file as a template.\n  Specify the ID of a spreadsheet that the Google account you are using\n  can access with write privileges.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Complete Google Sheets formatting support for gspread worksheets",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/robin900/gspread-formatting"
    },
    "split_keywords": [
        "spreadsheets",
        " google-spreadsheets",
        " formatting",
        " cell-format"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7bbc155a950da8a01885c08a672d0886fb979c62d2ed8570c2ca164c44e3506a",
                "md5": "8dbe3480af116079ab6938817a134ca2",
                "sha256": "9400a2369021ae6f6b31ed12eeddea35e5cfe1fd6c795487ed228eaf10fafad5"
            },
            "downloads": -1,
            "filename": "gspread_formatting-1.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8dbe3480af116079ab6938817a134ca2",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 22387,
            "upload_time": "2024-06-12T18:16:21",
            "upload_time_iso_8601": "2024-06-12T18:16:21.800870Z",
            "url": "https://files.pythonhosted.org/packages/7b/bc/155a950da8a01885c08a672d0886fb979c62d2ed8570c2ca164c44e3506a/gspread_formatting-1.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44b6811417edee4a1c7705c4ae54ea6fce749f15474b6c6deddb0f11ec303838",
                "md5": "fdb8267f6f141fb6e543597907d49c8a",
                "sha256": "ba88eab6940e8f37580fc3073e89848ab7a6eaab4ed91f43b731579280c14086"
            },
            "downloads": -1,
            "filename": "gspread-formatting-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fdb8267f6f141fb6e543597907d49c8a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 42833,
            "upload_time": "2024-06-12T18:16:23",
            "upload_time_iso_8601": "2024-06-12T18:16:23.482531Z",
            "url": "https://files.pythonhosted.org/packages/44/b6/811417edee4a1c7705c4ae54ea6fce749f15474b6c6deddb0f11ec303838/gspread-formatting-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-12 18:16:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "robin900",
    "github_project": "gspread-formatting",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "gspread-formatting"
}
        
Elapsed time: 2.95176s