Skip to content

Commit

Permalink
Merge pull request #1451 from nbwzx/dev
Browse files Browse the repository at this point in the history
add `get_notes`
  • Loading branch information
lavigne958 authored Apr 27, 2024
2 parents a51c13b + e0f90ed commit c740b88
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,32 @@ def unmerge_cells(self, name: str) -> JSONResponse:

return self.client.batch_update(self.spreadsheet_id, body)

def get_notes(self, default_empty_value: Optional[str] = None) -> List[List[str]]:
"""Returns a list of lists containing all notes in the sheet, or the empty list if the
sheet does not have a note.
.. note::
The resulting matrix is as long as the last row holding a note
(could be smaller than the last data row)
The resulting matrix is as large as the last column holding a note
(could be smaller than the last data column)
:param str default_empty_value: (optional) Determines which value to use
for cells without notes, defaults to None.
"""
params: ParamsType = {"fields": "sheets.data.rowData.values.note"}
res = self.client.spreadsheets_get(self.spreadsheet_id, params)
data = res["sheets"][self.index]["data"][0].get("rowData", [])
notes: List[List[str]] = []
for row in data:
notes.append([])
for cell in row.get("values", []):
notes[-1].append(cell.get("note", default_empty_value))

return notes

def get_note(self, cell: str) -> str:
"""Get the content of the note located at `cell`, or the empty string if the
cell does not have a note.
Expand Down

0 comments on commit c740b88

Please sign in to comment.