通过pythongspread从SQL数据库到googlesheet

通过pythongspread从SQL数据库到googlesheet,python,sql,google-sheets,gspread,Python,Sql,Google Sheets,Gspread,我正在尝试使用python和gspread从我的sql表填充一个已经创建的google工作表 我可以使用for循环一次更新一行工作表,但是我有很多数据要添加到工作表中,如果可能的话,我希望一次或多次更新一列 这里的任何建议都是我一直在使用的,我得到了一个错误:“Row”类型的对象不可JSON序列化 #!/usr/bin/python3 import gspread from oauth2client.service_account import ServiceAccountCredentials

我正在尝试使用python和gspread从我的sql表填充一个已经创建的google工作表

我可以使用for循环一次更新一行工作表,但是我有很多数据要添加到工作表中,如果可能的话,我希望一次或多次更新一列

这里的任何建议都是我一直在使用的,我得到了一个错误:“Row”类型的对象不可JSON序列化

#!/usr/bin/python3
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import dbconnect

#credentials for google 
gc = gspread.authorize(credentials)


worksheet = gc.open('NAMEOFWS').sheet1
cell_list = worksheet.range('A2:A86')

#connect to database using dbconnect and grab cursor
query = "select loc from table"
cursor.execute(query)

results = cursor.fetchall()
cell_values = (results)

for i, val in enumerate(cell_values):  
    cell_list[i].value = val  
worksheet.update_cells(cell_list)

我不知道如何使用gspread实现这一点,但您可以非常轻松地修改代码并使用pygsheets,它允许一次更新一列。此外,我不确定您的数据是什么样子的,因此下面的内容可能需要更改,或者您可能需要稍微更改一下数据集。希望这有帮助

import pygsheets

gc = pygsheets.authorize(service_file = 'client_secret2.json')

# Open spreadsheet and select worksheet
sh = gc.open('Api_Test')
wks = sh.sheet1

#update Column
notes = [1,2,3,4] #this is the dataset to getupdated in the column
wks.update_col(4, notes, 1)# 4 is the number of column, notes is the dataset to update, 1 skips the first row (I used a header)

感谢您的帮助,我实际上找到了一个方法,创建了一个空数组,将cursor.fetchall中的行附加到该数组中,然后使用for循环迭代并将每一行添加到单元格列表中,然后进行了一次大的更新。但我真的很感谢你的回应。我将在将来运行的报告中查找int pygsheets,这样做可能更容易。谢谢你。很高兴你明白了,谢谢你回来告诉我你是怎么做到的。那对我很有帮助!