pygsheets
pygsheets copied to clipboard
Unable to modify cell attributes
I ran the code below for a previous project a couple weeks ago with no issue. Today I find myself getting an error when trying to do anything other than adding the value to the cells. (note if I take all of the formatting code out of this block it will run fine)
No matter what I do, it returns the error
<HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/**/?fields=%2A&alt=json returned "Invalid requests[0].repeatCell: No grid with id: 1181929585". Details: "Invalid requests[0].repeatCell: No grid with id: 1181929585">
I am not sure what I'm doing wrong here.
querytitle = "Query"
new_wks = sh.add_worksheet(querytitle,rows=len(eatspromodetails_df),cols=len(eatspromodetails_df.columns))
wks = sh.worksheet_by_title(querytitle)
header = wks.cell("A2")
header.value = "Search results"
header.bold = True
header.set_text_format("bold",True)
header.set_text_format("fontSize",18)
header.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
rng = wks.get_values("A2", "K2",returnas="range")
rng.merge_cells()
searchbox = wks.cell("A1")
searchbox.value = "Search:"
searchbox.set_text_format("bold",True)
searchbox.set_text_format("foregroundColor",(0.9, 0.9, 0.9, 1.0))
searchbox.color = (0.0,0.0,0.0,0)
searchbox.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
modelcell = wks.cell("K1")
modelcell.set_text_format("bold",True)
modelcell.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
searchresults = wks.get_values("A3","K3",returnas="range").apply_format(modelcell)
cellquery = wks.cell("A3")
cellquery.value = querycell
Can you please show the traceback so that we can track down which line caused the issue.
Below is the full error which starts at header.set_text_fromat('bold',True) but this happens at every line that has to do with modifying the cell (font size, alignment, merge, etc).
---------------------------------------------------------------------------
HttpError Traceback (most recent call last)
<ipython-input-86-9ea5d9c8c8e3> in <module>
6 header.value = "Search results"
7 header.bold = True
----> 8 header.set_text_format('bold',True)
9 header.set_text_format('fontSize',18)
10 header.set_horizontal_alignment( pygsheets.custom_types.HorizontalAlignment.CENTER )
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/pygsheets/cell.py in set_text_format(self, attribute, value)
267
268 def set_number_format(self, format_type, pattern=''):
--> 269 """
270 Set number format of this cell.
271
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/pygsheets/cell.py in update(self, force, get_request, worksheet_id)
466 def get_json(self):
467 """Returns the cell as a dictionary structured like the Google Sheets API v4."""
--> 468 try:
469 nformat, pattern = self.format
470 except TypeError:
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/pygsheets/sheet.py in batch_update(self, spreadsheet_id, requests, **kwargs)
99 if not isinstance(requests, list):
100 requests = [requests]
--> 101
102 if self.batch_mode:
103 if spreadsheet_id in self.batched_requests:
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/pygsheets/sheet.py in _execute_requests(self, request)
357 value_range_end = list(format_addr(str(value_range_end), output='tuple'))
358 value_range_start = list(format_addr(str(value_range_start), output='tuple'))
--> 359 max_rows = value_range_end[0]
360 start_row = value_range_start[0]
361 for batch_start in range(0, num_rows, batch_length):
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
129 elif positional_parameters_enforcement == POSITIONAL_WARNING:
130 logger.warning(message)
--> 131 return wrapped(*args, **kwargs)
132
133 return positional_wrapper
/dsw/snapshots/f7a380cd-65fd-49ed-89e7-4ef44ca831cb/python3/lib/python3.6/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
935 callback(resp)
936 if resp.status >= 300:
--> 937 raise HttpError(resp, content, uri=self.uri)
938 return self.postproc(resp, content)
939
HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/<removed>:batchUpdate?fields=%2A&alt=json returned "Invalid requests[0].repeatCell: No grid with id: 1181929585". Details: "Invalid requests[0].repeatCell: No grid with id: 1181929585">