Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_notes #1451

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
lavigne958 marked this conversation as resolved.
Show resolved Hide resolved

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