nithinmurali / pygsheets

Google Sheets Python API v4

Home Page:https://pygsheets.readthedocs.io/en/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DataRange.apply_format() does not work for Date Format

rabdelazim opened this issue · comments

It's (always) possible I'm doing something wrong but I can't seem to get my column to set the Date format I need. Here's what I have:
First I get Columns "I" and "K" and move them to the first two columns (and delete the original columns I and K).

titles = client.spreadsheet_titles()
test_sheet = client.open(titles[0])
test_worksheets = test_sheet.worksheets()
active = test_worksheets[worksheet.index]
ord_to_ship_date = active.get_values("I1","I")
count = active.get_values("K1","K")
active.delete_cols(9)
active.delete_cols(10)
active.insert_cols(0,2)
active.update_values_batch(['A1:A', 'B1:B'], [ord_to_ship_date, count])

this works no problem.
Now the first column is a date field but it's in the wrong format. I need it to start with the day of the week followed by the day of month, month and year. I tried the following:

active.get_col(1, returnas = "range").apply_format(pygsheets.Cell('A2').set_number_format(pygsheets.FormatType.DATE, 'dddd+ mmmm yyy'))

This last call "succeeds" (i.e. no error message or anything. Just fails silently.) but doesn't update the format in my spreadsheet.

Any insight here would be greatly appreciated.

SO question for anyone interested: https://stackoverflow.com/questions/75654608/pygsheets-does-not-modify-date-format

It looks as though moving the column from one place to another adds a tick ` to the beginning of the value in the cell. I'm guessing this is to maintain the original formatting. Unfortunately the tick mark doesn't get removed before writing the data back to the spreadsheet so the date formatting doesn't get applied.
My workaround is to modify the date format before moving the column which makes me think this isn't quite a bug but would be nice to have better functionality around this. Theoretically it shouldn't matter if I change the format before or after the values are moved.