use*_*414 8 google-sheets r-googlesheets google-sheets-api
我找不到任何API,它使Rest API客户端能够将现有的Google表格导出到csv文件.
https://developers.google.com/sheets/
我相信应该有一种出口方式.
Ove*_*ryd 24
以下 URL 为您提供每个工作表的 Google 电子表格的 CSV。该表格必须可供公众访问,任何人都可以通过链接访问(未列出)。
您需要提供的参数是:
https://docs.google.com/spreadsheets/d/{{ID}}/edit)https://docs.google.com/spreadsheets/d/{{ID}}/gviz/tq?tqx=out:csv&sheet={{sheet_name}}
Run Code Online (Sandbox Code Playgroud)
使用该 URL,您可以运行 GET 请求来获取 CSV。或者将其粘贴到浏览器地址栏中。
还没有人提到gspread,所以我是这样做的:
#open sheet
sheet = gc.open_by_key(sheet_id)
#select worksheet
worksheet = sheet.get_worksheet(0)
#download values into a dataframe
df = pd.DataFrame(worksheet.get_all_records())
#save dataframe as a csv, using the spreadsheet name
filename = sheet.title + '.csv'
df.to_csv(filename, index=False)
Run Code Online (Sandbox Code Playgroud)
首先,您应该让任何人都可以访问文档。然后你得到url. 从这里url你应该id从大小写字母和数字中提取长篇。然后使用这个脚本。
#!/bin/bash
long_id="id_assigned_to_your_document"
g_id="number_assigned_to_card_in_google_sheet"
wget --output-document=temp.csv "https://docs.google.com/spreadsheets/d/$long_id/export?gid=$g_id&format=csv&id=$long_id"
Run Code Online (Sandbox Code Playgroud)
如果您在文件中只使用一张卡片,其编号为: g_id="0"
您可能遇到的问题与strange spaces获取的文件有关。我使用第二个脚本来处理它
#!/bin/bash
#Delete all lines beginning with a # from a file
#http://stackoverflow.com/questions/8206280/delete-all-lines-beginning-with-a-from-a-file
sed '/^#/ d' temp.csv |
# reomve spaces
# http://stackoverflow.com/questions/9953448/how-to-remove-all-white-spaces-from-a-given-text-file
tr -d "[:blank:]" |
# regexp "1,2" into 1.2
# http://www.funtoo.org/Sed_by_Example,_Part_2
sed 's/\"\([?]\?[0-9]*\),\([0-9]*\)\"/\1.\2/g' > out.csv
Run Code Online (Sandbox Code Playgroud)
正如 Sam 提到的,api 是更好的解决方案。现在有关于地址的很好的文档:
以生成具有 CSV 结构的输出为例。
您可以立即使用Drive API来执行此操作-请参阅https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents,但这将您限制在文档的第一页。Sheets API今天不提供导出为CSV的功能,但将来可能会提供。
| 归档时间: |
|
| 查看次数: |
10734 次 |
| 最近记录: |