Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the color of a cell in Google sheets

I'm using the Python Google Sheets API, and I'd like to read the color of an individual cell. I've read the docs, but I could only find info on how to retrieve the text from cell, not the color formatting.

like image 988
Roman Avatar asked Feb 01 '17 14:02

Roman


Video Answer


1 Answers

You can use the Method: spreadsheets.get to get the color of a specific cell.

Just pass the spreadsheetId and make sure you set to true the includeGridData parameter.

For example, this picture specifying the range B1.

enter image description here

By using this spreadsheets.get, you will get here a result of "backgroundColor": {"green": 1}, and not only the background color, you will also get here the fontFamily, fontSize and if it is bold, italic, strikethrough or underline.

You can try it by creating a spreadsheet, then follow the picture above.

Here is the request that I use.

GET https://sheets.googleapis.com/v4/spreadsheets/YOUR_SPREADSHEET_ID?includeGridData=true&ranges=B1&key={YOUR_API_KEY}
like image 84
KENdi Avatar answered Oct 18 '22 23:10

KENdi