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

Method format

gspread/worksheet.py:1439–1486  ·  view source on GitHub ↗

Format a list of ranges with the given format. :param str|list ranges: Target ranges in the A1 notation. :param dict format: Dictionary containing the fields to update. See `CellFormat`_ in the Sheets API for available fields. Examples:: # Set 'A4'

(
        self, ranges: Union[List[str], str], format: JSONResponse
    )

Source from the content-addressed store, hash-verified

1437 return self.client.batch_update(self.spreadsheet_id, body)
1438
1439 def format(
1440 self, ranges: Union[List[str], str], format: JSONResponse
1441 ) -> JSONResponse:
1442 """Format a list of ranges with the given format.
1443
1444 :param str|list ranges: Target ranges in the A1 notation.
1445 :param dict format: Dictionary containing the fields to update.
1446 See `CellFormat`_ in the Sheets API for available fields.
1447
1448 Examples::
1449
1450 # Set 'A4' cell's text format to bold
1451 worksheet.format("A4", {"textFormat": {"bold": True}})
1452
1453 # Set 'A1:D4' and 'A10:D10' cells's text format to bold
1454 worksheet.format(["A1:D4", "A10:D10"], {"textFormat": {"bold": True}})
1455
1456 # Color the background of 'A2:B2' cell range in black,
1457 # change horizontal alignment, text color and font size
1458 worksheet.format("A2:B2", {
1459 "backgroundColor": {
1460 "red": 0.0,
1461 "green": 0.0,
1462 "blue": 0.0
1463 },
1464 "horizontalAlignment": "CENTER",
1465 "textFormat": {
1466 "foregroundColor": {
1467 "red": 1.0,
1468 "green": 1.0,
1469 "blue": 1.0
1470 },
1471 "fontSize": 12,
1472 "bold": True
1473 }
1474 })
1475
1476 .. versionadded:: 3.3
1477 """
1478
1479 if isinstance(ranges, list):
1480 range_list = ranges
1481 else:
1482 range_list = [ranges]
1483
1484 formats = [CellFormat(range=range, format=format) for range in range_list]
1485
1486 return self.batch_format(formats)
1487
1488 def resize(
1489 self, rows: Optional[int] = None, cols: Optional[int] = None

Callers 15

__repr__Method · 0.80
get_worksheetMethod · 0.80
get_worksheet_by_idMethod · 0.80
transfer_ownershipMethod · 0.80
accept_ownershipMethod · 0.80
list_protected_rangesMethod · 0.80
copyMethod · 0.80
del_spreadsheetMethod · 0.80
__repr__Method · 0.80
row_valuesMethod · 0.80
col_valuesMethod · 0.80
update_cellsMethod · 0.80

Calls 1

batch_formatMethod · 0.95

Tested by 10

test_update_cellsMethod · 0.64
test_findMethod · 0.64
test_findallMethod · 0.64
test_formatMethod · 0.64
test_values_getMethod · 0.64
test_values_batch_getMethod · 0.64
prefixed_counterFunction · 0.64