How do I access (read, write) Google Sheets spreadsheets with Python?

前端 未结 8 742
盖世英雄少女心
盖世英雄少女心 2020-11-29 15:41

I am wondering if you can point me to an example of reading/writing to/from a google doc/spreadsheet using python.

I did look at google docs API here https://develo

相关标签:
8条回答
  • 2020-11-29 16:13

    Take a look at gspread port for api v4 - pygsheets. It should be very easy to use rather than the google client.

    Sample example

    import pygsheets
    
    gc = pygsheets.authorize()
    
    # Open spreadsheet and then workseet
    sh = gc.open('my new ssheet')
    wks = sh.sheet1
    
    # Update a cell with value (just to let him know values is updated ;) )
    wks.update_cell('A1', "Hey yank this numpy array")
    
    # update the sheet with array
    wks.update_cells('A2', my_nparray.to_list())
    
    # share the sheet with your friend
    sh.share("myFriend@gmail.com")
    

    See the docs here.

    Author here.

    0 讨论(0)
  • 2020-11-29 16:17

    I know this thread is old now, but here is some decent documentation on Google Docs API. It was ridiculously hard to find, but useful, so maybe it will help you some. http://pythonhosted.org/gdata/docs/api.html.

    I used gspread recently for a project to graph employee time data. I don't know how much it might help you, but here's a link to the code: https://github.com/lightcastle/employee-timecards

    Gspread made things pretty easy for me. I was also able to add logic in to check for various conditions to create month-to-date and year-to-date results. But I just imported the whole dang spreadsheet and parsed it from there, so I'm not 100% sure that it is exactly what you're looking for. Best of luck.

    0 讨论(0)
提交回复
热议问题