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 insert_note feature (#50) #818

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

lavigne958
Copy link
Collaborator

@lavigne958 lavigne958 commented Oct 2, 2020

Closes: #50
Add the 'insert_note' and 'clear_note' feature.
Notice:
The request to set a note on a cell with an empty string clears the note.
The 'insert_note' function only accepts string as note content

In the test I add I wanted to insert a note and some how through a different process check that the note is inserted but I could not find a way to verify the presence of the note.

I ran a couple of tests myself:

  • Insert a note with a text of size 1MiB => works, slow to complete but works
  • Over 1GiB text length it times out and an exception is triggered
  • I works on merged cells as well

Credits:
Thanks to @archeg that first provided a solution
Thanks to @hexvolt that provided the source code adapted to gpsread

Signed-off-by: Lavigne958 lavigne958@gmail.com

Add the 'insert_note' and 'clear_note' feature.
Notice:
The request to set a note on a cell with an empty string clears the note.
The 'insert_note' function only accepts string as note content

Signed-off-by: Lavigne958 <lavigne958@gmail.com>
@lavigne958
Copy link
Collaborator Author

Before merge, Can someone run the tests suite please ? I tried but I could not run it, I can not figure out the Oauth google service system.... I can connect to my spreadSheets but can not run the test suite with my credentials :-(

@burnash
Copy link
Owner

burnash commented Oct 7, 2020

Sure, I'll run the tests suite before I merge it. Thank you very much for the PR.

@lavigne958
Copy link
Collaborator Author

Hi, I managed to run the tests on my machine and it worked, and they all passed, good to go :-)
I mentioned it in a comment in a related Issue: #737 (comment)

@lavigne958
Copy link
Collaborator Author

Hi it has been a while isnce this PR is ready. I just give you a heads up in case.

@burnash
Copy link
Owner

burnash commented Feb 17, 2021

@lavigne958 sorry for the pause, looking at it now.

@burnash burnash merged commit 415e18b into burnash:master Feb 17, 2021
@burnash
Copy link
Owner

burnash commented Feb 17, 2021

Works like a charm. Thank you very much again!

@lavigne958 lavigne958 deleted the feature/add_remove_notes_#50 branch February 18, 2021 08:21
@billga
Copy link

billga commented Mar 7, 2021

First off: thanks to burnash for the whole gspread, it's been not only terribly useful, but fun to use.

Re: lavigne958's question about getting the note...
I'm not sure how to get a note with the gspread spreadsheet object, but I got it with the Google service object. There is likely a MUCH easier way to do this, hoping someone can tie this into the gspread model.

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery

scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name(filename, scope)
service = discovery.build('sheets', 'v4', credentials=creds)

With that service in hand, get the note(s):

fields = 'sheets/data/rowData/values/note'
ranges = [gspread.models.absolute_range_name(sheet.title, "A1")]
request = service.spreadsheets().get(spreadsheetId=sheet.spreadsheet.id, ranges=ranges, fields=fields)
note_json = request.execute()
try:
    note = note_json['sheets'][0]['data'][0]['rowData'][0]['values'][0]['note']  # <-- there's got to be a better way
except KeyError:
    note = None
print(note)

I was hoping to incorporate this into the Cell model, so that it could be 'just another field' in the Cell (e.g. cell.note). This would make it drop-dead simple to get/set. It looks like maybe passing in the right params to spreadsheet.values_get() would work?

@lavigne958
Copy link
Collaborator Author

Re: lavigne958's question about getting the note...
I'm not sure how to get a note with the gspread spreadsheet object, but I got it with the Google service object. There is likely a MUCH easier way to do this, hoping someone can tie this into the gspread model.

Hi @billga, to be honest I did not think about getting a note in gspread but only creating/updating/deleting a note.

I could have a look to it.
In your example the way you access notes could be implemented in gspread I suppose, I don't see any issue so far but still, I need to check it out properly and test first.

Thank you for pointing out the missing accessor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to add/remove comments and notes for cells
3 participants