Returns a list of :class:`gspread.cell.Cell` objects from a specified range. :param name: A string with range value in A1 notation (e.g. 'A1:A5') or the named range to fetch. :type name: str Alternatively, you may specify numeric boundaries. All values
(self, name: str = "")
| 372 | |
| 373 | @cast_to_a1_notation |
| 374 | def range(self, name: str = "") -> List[Cell]: |
| 375 | """Returns a list of :class:`gspread.cell.Cell` objects from a specified range. |
| 376 | |
| 377 | :param name: A string with range value in A1 notation (e.g. 'A1:A5') |
| 378 | or the named range to fetch. |
| 379 | :type name: str |
| 380 | |
| 381 | Alternatively, you may specify numeric boundaries. All values |
| 382 | index from 1 (one): |
| 383 | |
| 384 | :param int first_row: First row number |
| 385 | :param int first_col: First column number |
| 386 | :param int last_row: Last row number |
| 387 | :param int last_col: Last column number |
| 388 | |
| 389 | :rtype: list |
| 390 | |
| 391 | Example:: |
| 392 | |
| 393 | >>> # Using A1 notation |
| 394 | >>> worksheet.range('A1:B7') |
| 395 | [<Cell R1C1 "42">, ...] |
| 396 | |
| 397 | >>> # Same with numeric boundaries |
| 398 | >>> worksheet.range(1, 1, 7, 2) |
| 399 | [<Cell R1C1 "42">, ...] |
| 400 | |
| 401 | >>> # Named ranges work as well |
| 402 | >>> worksheet.range('NamedRange') |
| 403 | [<Cell R1C1 "42">, ...] |
| 404 | |
| 405 | >>> # All values in a single API call |
| 406 | >>> worksheet.range() |
| 407 | [<Cell R1C1 'Hi mom'>, ...] |
| 408 | |
| 409 | """ |
| 410 | range_label = absolute_range_name(self.title, name) |
| 411 | |
| 412 | data = self.client.values_get(self.spreadsheet_id, range_label) |
| 413 | |
| 414 | if ":" not in name: |
| 415 | name = data.get("range", "") |
| 416 | if "!" in name: |
| 417 | name = name.split("!")[1] |
| 418 | |
| 419 | grid_range = a1_range_to_grid_range(name) |
| 420 | |
| 421 | values = data.get("values", []) |
| 422 | |
| 423 | row_offset = grid_range.get("startRowIndex", 0) |
| 424 | column_offset = grid_range.get("startColumnIndex", 0) |
| 425 | last_row = grid_range.get("endRowIndex", self.row_count) |
| 426 | last_column = grid_range.get("endColumnIndex", self.col_count) |
| 427 | |
| 428 | if last_row is not None: |
| 429 | last_row -= row_offset |
| 430 | |
| 431 | if last_column is not None: |