Skip to content

Commit

Permalink
Merge pull request #1446 from burnash/doc/value_render_option_currency
Browse files Browse the repository at this point in the history
Improce README and documentation with value render options
  • Loading branch information
lavigne958 authored Mar 28, 2024
2 parents 3e5ca62 + 0ffbfe9 commit 909ab89
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ worksheet.batch_update([{
}])
```

### Get unformatted cell value or formula

```python
from gspread.utils import ValueRenderOption

# Get formatted cell value as displayed in the UI
>>> worksheet.get("A1:B2")
[['$12.00']]

# Get unformatted value from the same cell range
>>> worksheet.get("A1:B2", value_render_option=ValueRenderOption.unformatted)
[[12]]

# Get formula from a cell
>>> worksheet.get("C2:D2", value_render_option=ValueRenderOption.formula)
[['=1/1024']]
```

## Documentation

[Documentation]\: [https://gspread.readthedocs.io/][Documentation]
Expand Down
36 changes: 36 additions & 0 deletions docs/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,42 @@ If you want to get a cell formula:
cell = worksheet.cell(1, 2, value_render_option='FORMULA').value
Getting Unformatted Cell Value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Get the Unformatted value from a cell.
Example: cells formatted as currency will display with the selected
currency but they actual value is regular number.

Get the formatted (as displayed) value:

.. code:: python
worksheet.get("A1:B2")
Results in: ``[['$12.00']]``

Get the unformatted value:

.. code:: python
from gspread.utils import ValueRenderOption
worksheet.get("A1:B2", value_render_option=ValueRenderOption.unformatted)
Results in: ``[[12]]``

Getting Cell formula
~~~~~~~~~~~~~~~~~~~~

Get the formula from a cell instead of the resulting value:

.. code:: python
from gspread.utils import ValueRenderOption
worksheet.get("G6", value_render_option=ValueRenderOption.formula)
Resulsts in: ``[['=1/1024']]``


Getting All Values From a Row or a Column
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 909ab89

Please sign in to comment.