Google电子表格Python API阅读特定栏目



关于使用python的谷歌电子表格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——我认为列表提要在遇到空白时会停止阅读。对不起,我忘记了细节。但我很久以前就放弃了列表订阅源,转而使用cellfeed。

最新更新