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
)
| 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 |