Add support for `textFormat.foregroundColorStyle`
iprunache opened this issue · comments
get_default_format
on 0.0.7
fails because it cannot parse default format props for a Sheet.
File "/usr/local/lib/python3.8/site-packages/gspread_formatting/__init__.py", line 41, in get_default_format
return CellFormat.from_props(fmt) if fmt else None
File "/usr/local/lib/python3.8/site-packages/gspread_formatting/__init__.py", line 220, in from_props
return _props_to_component(_underlower(cls.__name__), props)
File "/usr/local/lib/python3.8/site-packages/gspread_formatting/__init__.py", line 185, in _props_to_component
v = _props_to_component(item_alias, v, True)
File "/usr/local/lib/python3.8/site-packages/gspread_formatting/__init__.py", line 185, in _props_to_component
v = _props_to_component(item_alias, v, True)
File "/usr/local/lib/python3.8/site-packages/gspread_formatting/__init__.py", line 176, in _props_to_component
raise ValueError("No format component named '%s'" % class_alias)
ValueError: No format component named 'foregroundColorStyle'
This seems to be caused by a recent change in the Google Sheets API, see the multiple mentions of foregroundColorStyle
and backgroundColorStyle
in the documentation:
https://developers.google.com/resources/api-libraries/documentation/sheets/v4/python/latest/sheets_v4.spreadsheets.html
Thanks for the bug report and the links to API documentation. I'm readying a new release that supports these two new CellFormat fields (and the accompanying ColorStyle).
Some complications:
-
I can successfully set via live API the backgroundColorStyle via userEnteredFormat. But when I read back the userEnteredFormat for the cell, backgroundColorStyle is absent. It is present in effectiveFormat, however.
-
The REST API documentation does not yet mention either backgroundColorStyle or foregroundColorStyle: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellFormat . These two fields are mentioned in the C# and Python library documentation, but not the REST API. I wonder what's going on here.
Nonetheless, I'm adding support for these new fields and objects since they're backwards compatible.
@iprunache Release is up on PyPI:
Thanks @robin900 for the quick fix!
The API change is indeed very stealthy. Perhaps we'll get an update on the REST API soon. It doesn't help that there aren't any easily available release notes for the sheets API.
@iprunache please let me know that release 0.0.8 works for you...
@robin900 I no longer have any issues on my use case with 0.0.8. Thanks again for the fix!