使用 google drive API 下载 csv 格式的电子表格 [英] Using the google drive API to download a spreadsheet in csv format

查看:17
本文介绍了使用 google drive API 下载 csv 格式的电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个显而易见的问题,我很抱歉,我对 API 还是很陌生.我正在使用 python drive api 库,并尝试将 google 电子表格下载为 csv.
当我使用 files.get 时,它会吐出一个没有 downloadUrl 的文件,并且在导出链接字段中没有text/csv"键.
如果不可能,我可以找到一种解决方法,但我希望它是,因为可以手动执行 (file->download_as->csv)

I'm sorry if this is an obvious question, I'm still pretty new to the API. I'm using the python drive api library, and trying to download a google spreadsheet as a csv.
When I used files.get, it spat out a file with no downloadUrl, and with no 'text/csv' key in the export links field.
If it's not possible, I can find a workaround, but I'm hoping it is, since it is possible to do manually (file->download_as->csv)

我需要使用谷歌文档列表api吗?

Do I need to use the google document list api?

谢谢,马特

推荐答案

更新:我已经发布了 另一个答案适用于电子表格 v4 API.

Update: I have posted another answer that works with the Spreadsheets v4 API.

旧答案:

Alain 的回答是正确的,但您还需要设置 gid=parameter 来指定要导出的工作表.

The answer from Alain is correct, but you also need to set the gid=parameter to specify which worksheet to export.

例如,如果您的应用程序/pdf"导出链接是这样的:

For example, if your 'application/pdf' export link is like this:

docs.google.com/feeds/download/spreadsheets/Export?key=<FILE_ID>&exportFormat=pdf

您可以将其更改为下载第一个工作表:

You can just change it to this to download the first worksheet:

docs.google.com/feeds/download/spreadsheets/Export?key<FILE_ID>&exportFormat=csv&gid=0

虽然没有可靠的方法通过 API 获取给定工作表的 gid 并且它们不是从零开始的索引,但存在一些问题.如果您删除工作表,则该 gid 不会被重用.不过,您可以在浏览器的 URL 中看到 gid,因此如果您的工作表信息是不变的,您可以从那里获取.请参阅 http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=1813http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3240 了解有关该问题的更多信息.

There is a bit of a problem, though as there is no reliable way to get the gid for a given worksheet through the API and they are not zero based indexes. If you delete a worksheet, that gid does not get reused. You can see the gid in the URL in your browser though, so if your worksheet information is constant you can just get that from there. See http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=1813 and http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3240 for more info on that problem.

这篇关于使用 google drive API 下载 csv 格式的电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆