我正在尝试使用pyhton更新值单元格。我想用一个变量的值更新单元格。这是我的代码:
for plant in plants:
# Get list of assets
response = client.get_asset_list(organization_id=client.organization_id)
if len(response) == 0:
print('No assets in this plant')
else:
for asset in response:
print(asset["assetName"],':',asset["lastSyncTimeStamp"])
return True
这是响应:
sec0 TOEME-9089 : 2020-06-15T06:57:50Z
Ventilador FCH 3 : 2020-06-15T06:54:33Z
sec1 TOEME-9528 : 2020-06-15T07:13:37Z
sec7 TOEME-7086 : 2020-06-15T06:59:33Z
sec4 TOEME-09094 : 2020-06-15T06:59:11Z
PC ED FL/2 : 2020-06-15T06:39:25Z
Ventilador FCH 2 : 2020-06-11T23:57:23Z
Dardelet PV-4 : 2020-06-09T10:14:25Z
Ventilador FCH 1 : 2020-06-09T11:22:29Z
Movimiento DV 3 : 2020-06-10T05:54:09Z
Movimiento DV 2 : 2020-06-11T04:48:48Z
MOLINO BR63/1 : 2020-06-08T06:25:10Z
PC N°2 SAC : 2020-06-08T06:36:03Z
Molino BR63/2 : 2020-06-08T06:39:47Z
Prueba 1 : 2020-05-12T06:09:35Z
VTL aire Combustión I : 2020-05-15T16:41:59Z
VTL aire combustión II : 2020-05-15T16:57:55Z
我想将此代码放在单元格上,为此,我在同一脚本的第一个代码之后编写以下代码:
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.\
from_json_keyfile_name('Smartsensors-02d98c39eaac.json',scope)
client=gspread.authorize(credentials)
sheet = client.open('tutorial1').sheet1
# Select a range
cell_list = sheet.range('A1:A60')
for cell in cell_list:
cell.value = (asset["assetName"],':',asset["lastSyncTimeStamp"])
# Update in batch
sheet.update_cells(cell_list)
我拥有所有库以及所有已安装和导入的库。如果我想使用“ Hello World”之类的简单值而不是使用变量来更新脚本,则该脚本有效。谢谢