简体   繁体   中英

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.

ie, I am able to get the feed from the worksheet. Now I need 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数据API具有Python绑定,包括电子表格: 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM