[英]Using gspread to extract sheet ID
似乎找不到任何答案,但是是否有任何可以获取工作表 ID 的函数/方法?
目前,我的代码如下所示:
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
....code to authorize credentials goes here....
sheet = client.open(str(self.googleSheetFile)).worksheet(str(self.worksheet))
client.import_csv('abcdefg1234567abcdefg1234567', contents)
但我不想硬编码abcdefg1234567abcdefg1234567
。 有什么我可以做的,比如sheet.id()
?
我相信你的目标如下。
import_csv
,您需要从sheet = client.open(str(self.googleSheetFile)).worksheet(str(self.worksheet))
检索电子表格 ID。 在这种情况下,您可以从client.open(str(self.googleSheetFile))
检索电子表格 ID。 因此,请按如下方式修改您的脚本。
sheet = client.open(str(self.googleSheetFile)).worksheet(str(self.worksheet))
client.import_csv('abcdefg1234567abcdefg1234567', contents)
spreadsheet = client.open(str(self.googleSheetFile))
sheet = spreadsheet.worksheet(str(self.worksheet))
client.import_csv(spreadsheet.id, contents)
当我看到gspread的文档时,它是这样说的。 所以请注意这一点。
此方法删除所有其他工作表,然后完全替换第一个工作表的内容。
这个修改后的脚本假设您已经能够使用带有 gspread 的 Sheets API 获取和放置 Google 电子表格的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.