how can i color several ranges background in google sheet

  Kiến thức lập trình

I have an api to color the background but when I need it to iterate over few ranges the code crash after too many calls.
So I thought on 2 optional solution:

  1. Rearrange the sheet so all the ranges of the same color will become one big range
  2. change the color api to be able to color a few ranges simultaneously.

I am having trouble execute those solutions and be grateful for help.

current API for coloring the background:

    def color(self, sheet_id, red=1.0, green=1.0, blue=1.0, start_row=0, end_row=0):
        try:
            service = build('sheets', 'v4', credentials=self.creds)
            request = {
                "requests": [
                    {
                        "repeatCell": {
                            "range": {
                                "sheetId": sheet_id,
                                "startRowIndex": start_row,
                                "endRowIndex": end_row
                            },
                            "cell": {
                                "userEnteredFormat": {
                                    "backgroundColor": {
                                        "red": red,
                                        "green": green,
                                        "blue": blue
                                    }
                                }
                            },
                            "fields": "userEnteredFormat(backgroundColor)"
                        }

                    }
                ]
            }
            return service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheet_id, body=request).execute()
        except Exception as err:
            handle_sheets_error("color", "general_error", err=err)

New contributor

Aviv Gaziel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT