pygsheets
pygsheets copied to clipboard
Date formatting not changing
Hi! Thanks for your nice library to interact with the Google sheets API. I'm seeing some odd behaviour when trying to update the date format.
I run this code:
date = wks.get_values(start='C3', end='C3', returnas='cells')
wks.update_value('C3', curr_date_reformat)
c1 = wks.cell('C3')
c1.set_number_format(pygsheets.FormatType.DATE, 'ddd d mmm')
date = wks.get_values(start='C3', end='C3', returnas='cells')
But only some of the values change to the right format (even when I loop back and forth between US and UK datetime formatting, thought that might fix it but it doesn't):
2019-05-27
[[<Cell C3 '27/05/2019'>]]
2019-06-03
[[<Cell C3 'Mon 3 Jun'>]]
2019-06-10
[[<Cell C3 'Mon 10 Jun'>]]
2019-06-17
[[<Cell C3 '17/06/2019'>]]
2019-06-24
[[<Cell C3 '24/06/2019'>]]
2019-07-01
[[<Cell C3 'Mon 1 Jul'>]]
Any ideas you have to get around this would be great!
Okay so I managed to get it to work by running the code in this order, but that means there must be something funny in the datetime formatting even though the spreadsheet is set to UK format, I'm not sure if it is on the Google API end or in pygsheets but if there is a cleaner way let me know!
curr_date_reformat = datetime.datetime.strftime(curr_date_dt,'%m/%d/%Y')
wks.update_value('C3', curr_date_reformat)
c1 = wks.cell('C3')
c1.set_number_format(pygsheets.FormatType.DATE, 'ddd d mmm')
date = wks.get_values(start='C3', end='C3', returnas='cells')
curr_date_reformat = datetime.datetime.strftime(curr_date_dt,'%d/%m/%Y')
wks.update_value('C3', curr_date_reformat)
c1 = wks.cell('C3')
c1.set_number_format(pygsheets.FormatType.DATE, 'ddd d mmm')
date = wks.get_values(start='C3', end='C3', returnas='cells')