-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsheets.py
36 lines (21 loc) · 857 Bytes
/
sheets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint as pp
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json",scope)
client = gspread.authorize(creds)
sheet = client.open("Students Marks ").sheet1
#Getting data from the sheet
data = sheet.get_all_records()
pp(data)
#Get the specific row, column and cell from the sheet
row = sheet.row_values(3)
col = sheet.col_values(3)
cell = sheet.cell(1,2).value
pp(cell)
#Inserting data in your sheet
insertRow = ["Zayn","Malik",12]
sheet.insert_row(insertRow,7)
print("The row has been added")
sheet.delete_row(2)
pp("The row has been deleted")