MCPcopy
hub / github.com/burnash/gspread / batch_format

Method batch_format

gspread/worksheet.py:1372–1437  ·  view source on GitHub ↗

Formats cells in batch. :param list formats: List of ranges to format and the new format to apply to each range. The list is composed of dict objects with the following keys/values: * range : A1 range notation * format : a valid dict object

(self, formats: List[CellFormat])

Source from the content-addressed store, hash-verified

1370 return response
1371
1372 def batch_format(self, formats: List[CellFormat]) -> JSONResponse:
1373 """Formats cells in batch.
1374
1375 :param list formats: List of ranges to format and the new format to apply
1376 to each range.
1377
1378 The list is composed of dict objects with the following keys/values:
1379
1380 * range : A1 range notation
1381 * format : a valid dict object with the format to apply
1382 for that range see `CellFormat`_ in the Sheets API for available fields.
1383
1384 .. _CellFormat: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#cellformat
1385
1386 Examples::
1387
1388 # Format the range ``A1:C1`` with bold text
1389 # and format the range ``A2:C2`` a font size of 16
1390
1391 formats = [
1392 {
1393 "range": "A1:C1",
1394 "format": {
1395 "textFormat": {
1396 "bold": True,
1397 },
1398 },
1399 },
1400 {
1401 "range": "A2:C2",
1402 "format": {
1403 "textFormat": {
1404 "fontSize": 16,
1405 },
1406 },
1407 },
1408 ]
1409 worksheet.batch_format(formats)
1410
1411 .. versionadded:: 5.4
1412 """
1413
1414 # No need to type more than that it's only internal to that method
1415 body: Dict[str, Any] = {
1416 "requests": [],
1417 }
1418
1419 for format in formats:
1420 range_name = format["range"]
1421 cell_format = format["format"]
1422
1423 grid_range = a1_range_to_grid_range(range_name, self.id)
1424
1425 fields = "userEnteredFormat(%s)" % ",".join(cell_format.keys())
1426
1427 body["requests"].append(
1428 {
1429 "repeatCell": {

Callers 1

formatMethod · 0.95

Calls 2

a1_range_to_grid_rangeFunction · 0.85
batch_updateMethod · 0.45

Tested by

no test coverage detected