如何使用新的(V3)谷歌驱动器API导出特定工作表 [英] How to export specific sheet using new (v3) google drive API

查看:298
本文介绍了如何使用新的(V3)谷歌驱动器API导出特定工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从电子表格(在Google云端硬盘上)下载特定工作表,但无法找到这样做的方法。我使用Python客户端API库(v3)并在export_media()函数中传递file_id和mimeType,如下所示:

  request = service.files()。export_media(fileId = file_id,mimeType ='text / csv')
media_request = http.MediaIoBaseDownload(local_fd,request)

此代码始终导出位于第一位的表单。您能否描述一种方法,我可以通过提供gid或任何其他参数来下载特定的表单/表单。 我不知道我认为Drive API有一个功能可以指定一个表名。



两个解决方法可以让人记住...


  1. 您可以使用Sheets API( https://developers.google.com/sheets/api/reference/rest/ )并编写自己的csv格式器。这听起来比现在更复杂。这可能是10行代码,特别是如果您使用Tab Separated而不是逗号分隔。

  2. 使用Google Spreadsheet File / Publish到Web 功能发布任何给定工作表的csv。请注意,内容将是公开的,所以任何拥有该链接的人都可以阅读这些数据。


I am trying to download specific sheet from a spread-sheet (on Google Drive) but unable to find a method to do so. I am using Python Client API library (v3) and passing file_id and mimeType in export_media() function as shown below:

request = service.files().export_media(fileId=file_id,mimeType='text/csv')
media_request = http.MediaIoBaseDownload(local_fd, request)

This code always export the sheet which is present at first place. Can you please describe a method through which I can download specific sheet/sheets by providing gid or any other parameter.

解决方案

I don't think the Drive API has a feature to specify a sheet name.

Two workarounds spring to mind...

  1. You could use the Sheets API (https://developers.google.com/sheets/api/reference/rest/) and write your own csv formatter. It sounds more complex than it is. It's probably 10 lines of code, especially if you go for Tab Separated instead of Comma Separated.

  2. Use the Google Spreadsheet File/Publish to the Web feature to publish a csv of any given sheet. Note that the content will be public, so anybody with the link (which is pretty obtuse) would be able to read the data.

这篇关于如何使用新的(V3)谷歌驱动器API导出特定工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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