【问题标题】:Google Spreadsheet Python API read specific columnGoogle Spreadsheet Python API 读取特定列
【发布时间】:2014-11-05 15:19:55
【问题描述】:

我有 2 个关于使用 python 的 google 电子表格的 api 的问题。我的谷歌电子表格如下:

a b
1 2
3 4

5 6

当我运行下面的脚本时,我只会得到

root@darkbox:~/google_py# python test.py
1
2
3
4

我只想得到第 1 列,所以我想看看
1
3
5
我的第二个问题是考虑行之间有一个空格我的脚本没有得到第二部分(在这种情况下应该是 5)
如何获取指定的列并忽略空格?

#!/usr/bin/env python
import gdata.docs
import gdata.docs.service
import gdata.spreadsheet.service
import re, os

email = 'xxxx@gmail.com'
password = 'passw0rd'
spreadsheet_key = '14cT5KKKWzup1jK0vc-TyZt6BBwSIyazZz0sA_x0M1Bg' # key param
worksheet_id = 'od6' # default
#doc_name = 'python_test'
def main():
    client = gdata.spreadsheet.service.SpreadsheetsService()
    client.debug = False
    client.email = email
    client.password = password
    client.source = 'test client'
    client.ProgrammaticLogin()

    q = gdata.spreadsheet.service.DocumentQuery()
    feed = client.GetSpreadsheetsFeed(query=q)
    feed = client.GetWorksheetsFeed(spreadsheet_key)
    rows = client.GetListFeed(spreadsheet_key,worksheet_id).entry

    for row in rows:
       for key in row.custom:
         print "%s" % (row.custom[key].text)
    return
if __name__ == '__main__':
    main()

【问题讨论】:

  • 使用 CellFeed,您返回的单元格数据包括包含行/列信息的单元格 ID。

标签: google-sheets-api google-api-python-client


【解决方案1】:

忽略空格: 建议您切换到 CellFeed - 我认为列表提要在遇到空白时会停止读取。对不起,我忘记了细节。但是很久以前我放弃了 List feed 并切换到 cellfeed。

【讨论】:

  • 问题在于使用 CellFeed 更新许多单元格需要很长时间(许多 api 调用)。
  • @MS_SL 快速更新:stackoverflow.com/questions/8402733/… 做了一个测试,花了 5 秒时间将 4000 个单元格插入到 40,000 个单元格表中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 2013-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多