如何将从Google表格提取的文件成功导出为.csv格式?

时间:2019-01-28 01:57:00

标签: python-3.x

我有一个代码,可以使用Google Drive / Google Sheet API(下面的代码)从Google表格中提取表格。我需要将表导出为csv格式。我尝试了几种csv编写代码,但结果仅返回该表的假定标题。

我尝试添加如下所示的csv编写器代码,但它只给我提供标头,而没有任何其他数据。

import gspread
from oauth2client.service_account import ServiceAccountCredentials

# use creds to create a client to interact with the Google Drive API
scope =['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

sheet = client.open('PBI Dashboard Refresh Cadence').sheet1

# Extract and print all of the values
list_of_hashes = sheet.get_all_records()

myFile = open('sample.csv', 'w')  
 with myFile:  
   writer = csv.writer(myFile)
   writer.writerows(list_of_hashes)

创建的csv仅给我表的假定标题。

0 个答案:

没有答案