日期/时间输出在 Google Sheet 中的变量前面有单引号

Aar*_*ron 2 python google-sheets

我有一些代码可以将一些输出导出到 Google 表格。我为此使用的命令是:

row = [timestamp, float(temperature), float(humidity), current_temperature, current_humidity, current_pressure, weather_description]
sheet.insert_row(row, index)
Run Code Online (Sandbox Code Playgroud)

问题是时间戳变量在插入到工作表中时在其自身前面添加了一个单引号,但是在使用 时print(timestamp),该引号不存在。

Google 表格中单元格中的日期/时间

这使得事情变得很困难,因为我无法在输出前面制作任何带有该引号的图表。我使用的时间命令如下:

now = datetime.now()
timestamp = now.strftime("%m/%d/%Y%l:%M:%S %p")
Run Code Online (Sandbox Code Playgroud)

如何获得前面没有单引号的时间戳?

fan*_*ard 5

尝试sheet.insert_row(row, index, value_input_option='USER_ENTERED')

默认情况下,value_input_option将是RAW

用户输入的值将不会被解析并按原样存储。

使用USER_ENTERED

这些值将被解析,就像用户将它们输入到 UI 中一样。数字将保留为数字,但字符串可能会转换为数字、日期等,遵循通过 Google 表格 UI 在单元格中输入文本时应用的相同规则。

https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption