我需要在文件系统上下载 Google 电子表格,我正在使用 Gspread 从 Google Drive 中读取文件,效果很好。
我尝试导出为 CSV,但这当然会丢弃格式。
json_key = json.load(open('/googleDriveCredentials.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
wks = gc.openall()
# processing first workbook
spreadsheet = wks[1]
# Creating CSV file which doesn't preserve formatting
for i, worksheet in enumerate(spreadsheet.worksheets()):
filename = 'somefile' + str(i) + '.csv'
with open(filename, 'wb') as f:
writer = csv.writer(f)
writer.writerows(worksheet.get_all_values())
我想知道我是否可以做这样的事情
worksheet.export("/myFolder")