pygsheets
pygsheets copied to clipboard
Get cell format when reading from a Google Spreadsheet
Dear Team,
First of all, thanks a lot for this API. It is saving a lot of time when I try to pull out data from a Google Spreadsheet or update data.
I would like to know if it is possible to detect the format of a particular cell range/row/cell when reading from gsheet. Is it possible to read only the Bold font items or exclude strike-through items or read only a particular coloured rows using this app. I did find API docs on setting formatting for cells but did not find anything for getting the formats.
Thanks, Padma
Hi Padma, when you create a cell, only the value of the cell will be set, if you want to get all the cell properties call the fetch function. Now for getting formats, the properties are not documented, thanks for letting us know.
c1 = wks.Cell('A1')
c1.fetch()
c1.text_format['bold']
Now about getting only data based on format, I don't think pygsheets can do that. Also i am doubt full if the even the raw api can do it. Incase you find a way please let us know.
I don't think the API can get data based on format, but we could implement functions which allow for easier access to the format params (e.g. a bold property etc.) The question is if many people would want that and how far we would want do bring this.
Then it would be possible to create a spreadsheet/worksheet function which can filter based on various properties. (e.g. get only CENTER aligned cells). This would be a functionality just in pygsheets and would be fully independent of the API.
@Kordishal yes it can be achieved like that. But i am not sure if many people would want that. And by adding each format as property we would be polluting the cell object.
The alternative would be to have a spreadsheet/worksheet function which like filter(attribute, value) where the attribute refers to a specific format attribute as string and the value you are looking for.
Without implementing all the attributes, but based on keys. This way would simply need to properly document this filter function but not add more properties on cell. It would then return a list of cells which have the specified value in this attribute.
Example: filter('strikethrough', False) -> return all items which have strikethrough set so false.
An implementation would then assume all unspecified values to not be present. Since most of the format values are implemented as dictionaries anyway this would not be the biggest problem.