0
votes

So i have a python script that updates a google sheet with the date and other data corresponding to it. Right now, i just add a row with the data i want inside it

row = [str(dateIn), outcome, numMap, oppAvg]
index = 2
sheet.insert_row(row, index) # this adds a row to the second row, shifts everything down.

When it shows up in the sheet, its just saves it there as a string.

Can i make that specific cell, or even that column to be formatted to a Date? I've already tried setting that column to Date in the sheet, then adding the date. Same thing.

1
I have to apologize for my poor English skill. Can I ask you about your question? 1. I cannot understand about specific cell and formatted to a Date of Can i make that specific cell, or even that column to be formatted to a Date?. Can I ask you about the detail of it? 2. Are you using gspread? From your script, I couldn't understand whether my understanding is correct. - Tanaike
@Tanaike Yes i am using gspread so google sheets has the cell format.So it can be a number, date, currency. My python program fills the date to a cell, and it selects the cell type automatically. Id like the cell type to be a "date" format" - AryanK
Thank you for replying. From your replying, I proposed a modified script as an answer. Could you please confirm it? If I misunderstood your question and that was not the direction you want, I apologize. - Tanaike

1 Answers

0
votes
  • You want to put the value of date to a cell of Google Spreadsheet as the date object using gspread.
  • You have already been able to get and put values for Google Spreadsheet using Sheets API.

I could understand like above. If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

Modification point:

  • In this case, I think that when value_input_option is used to the method of insert_row, your goal can be achieved.

Modified script:

row = ["2020/03/26"]
index = 2
sheet.insert_row(row, index, "USER_ENTERED")

or

row = ["2020/03/26"]
index = 2
sheet.insert_row(row, index, value_input_option="USER_ENTERED")
  • In this case, the string value of "2020/03/26" is put to a cell of Google Spreadsheet as the date object.
  • When USER_ENTERED is used, the number is also put as the number.

References: