-
Notifications
You must be signed in to change notification settings - Fork 950
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
Unable to insert datetime object #511
Comments
First of all, thanks for trying a new version :) It's a good point. Currently, there's no such functionality. You're right, in the previous version (0.6.2), you could just pass an arbitrary object and it'll be converted to a string representation with the help of Lines 460 to 487 in a6fefba
This is where it happens: In the new version, the implicit conversion is no longer needed, since API v4 uses JSON. In 2.0.0 the values go to the Sheets API as is: Lines 511 to 551 in a6fefba
And that's where this age old problem arises. On the one hand, the idea of implicitly casting everything to string is not my favorite. On the other hand, for certain types having an implicit cast can improve end-user experience. One option is to implement something like
But I haven't yet figured out how to squeeze it in properly. |
I'm not sure how helpful this will be, but I was able to write a date to the sheet by converting it to a count of the number of days since the Google Sheets epoch date of "1899-12-30" (https://developers.google.com/sheets/api/guides/concepts). Something like: |
@cgmorton thanks so much I was looking for a solution all over the web, this worked on pyton 2.7: (date.today() - date(1899, 12, 30)).days |
* burnash/gspread#511 for the json issue * burnash/gspread#524 for the escaping issue
The main issue here is:
I would agree that everything should be converted to its string representation as in all cases we can't send a I first fix would be: make sure everything sent over is a string or raise otherwise. this would prevent the raise of an underlying library that stops because it cannot read this json object. |
You could use this function, it worked for me: Imports:
Lets have a variable now as datetime object:
then pass now to the following function as string.
This way your entered datetime will be recognized by google sheet as if it was entered by a person. If you want to know more about how to use gspread follow this link. Entering multiple values could be done as well by replacing with:
|
Environment info
Operating System: Windows 10
Python version: 2.7.12
gspread version: 2.0.0
Steps to reproduce
Traceback:
I know it is possible to convert to a string before inserting however in previous gspread versions I could insert a datetime object and it would format the datetime using the formatting from the google sheet. Is there anyway this kind of functionality could be replicated in 2.0.0?
The text was updated successfully, but these errors were encountered: