【发布时间】:2023-04-02 20:50:01
【问题描述】:
这是我第一次使用 google sheet api。所以,我试图加粗谷歌工作表的第一行。但这样做时我得到错误 'Worksheet' object has no attribute 'spreadsheets'。我已经提到了下面的代码。请指出我做错了什么。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json",scope)
client = gspread.authorize(creds)
sheet = client.open("SheetsAPI Practice").sheet1
req = { "repeatCell": {
"range": {
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 1
},
"cell": {
"userEnteredFormat": {
"textFormat": {
"bold": True
}
}
},
"fields": "userEnteredFormat.textFormat.bold"
}
}
sheet.spreadsheets().batchUpdate(spreadsheetId=sheet.id,body=req).execute()
此行发生错误-
sheet.spreadsheets().batchUpdate(spreadsheetId=sheet.id,body=req).execute()
【问题讨论】:
-
我的回答是否向您展示了您想要的结果?你能告诉我吗?这对我学习也很有用。如果这可行,与您有相同问题的其他人也可以将您的问题作为可以解决的问题。如果您对我的回答有疑问,我深表歉意。到时候,可以问一下你现在的情况吗?我想学习解决你的问题。
-
请检查您答案的评论部分。非常感谢您的关心。
标签: python excel google-sheets-api