开发者

How to write a python script to manipulate google spreadsheet data

I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell.

i.e, I am able to get the feed from the worksheet. Now I ne开发者_开发问答ed to get data(string type?) from each of the cells to make a comparison and for input.

How exactly can I do that?


There's another spreadsheet library worth to look at: gspread. I've used Google's data libary mentioned above and to me the provided api is weird. You need to extract spreadsheet's key to start working with this spreadsheet.

Here it's a way simpler. If you need to fetch the data from a cell you can just open a worksheet and get the value:

g = gspread.login('your@gmail.com', 'password')

worksheet = g.open('name_of_the_spreadsheet').get_worksheet(0)

# Say, you need A2
val = worksheet.cell(2, 1).value

# And then update
worksheet.update_cell(2, 1, '42') 


Google data api has a Python binding including for spreadsheets: http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html


Maybe you can use this library http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html ?


gspread is probably the fastest way to begin this process, however there are some speed limitations on updating data using gspread from your localhost. If you're moving large sets of data with gspread - for instance moving 20 columns of data over a column, you may want to automate the process using a CRON job.


There's another spreadsheet library : pygsheets. Its similar to gspread, but uses google api v4. Hence provides more options.

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")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜