使用谷歌驱动器API以csv格式下载电子表格 [英] Using the google drive API to download a spreadsheet in csv format

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

问题描述

如果这是一个明显的问题,我很抱歉,我对这个API仍然很陌生。
我正在使用python驱动api库,并试图下载一个csv的谷歌电子表格。

当我使用files.get时,它吐出一个没有downloadUrl的文件,没有'text / csv'键出口链接字段。

如果这是不可能的,我可以找到一个解决方法,但我希望它是,因为它是可能的手动(文件> download_as-> csv)



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



谢谢,
Matt

解决方案

Alain的答案是正确的,但您还需要设置 gid =参数来指定要导出的工作表。例如,如果您的'application / pdf'导出链接如下所示:

  $ b 

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

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

  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=1813 http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3240 了解更多有关该问题的信息。


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)

Do I need to use the google document list api?

thanks, Matt

解决方案

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

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

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.

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

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