My goal is to update a Google Sheets document by replacing the content of its first sheet by a table of my own data (that is, a table of instances against attributes of a class). I have attempted to use the module gspread to do so but it hasn't been working out so well: If I run the line
client.open("GoogleSheetName").sheet1.update('A1:R181',Member.display().to_json())
(where Member is my class, and display() is my own class method which simply converts my data to a pandas dataFrame object.), the whole Member.display().to_json()
string is put in the cell A1, as though it is never unpacked and simply left as one string.
If I use the json module and dump my data using json.dumps(Member.display().to_dict())
, I obtain the same problem.
I also attempted to simply change the data to Member.display().to_dict()
, in which case I get an 'Invalid JSON payload received
' error.
It seems like the data may need to be in matrix format for it to work i.e. [[..,..,..][..,..,..]...]
, as that is the only format that has worked properly in my case. I know it works because when I test the API by running
client.open("GoogleSheetName").sheet1.update('A1:B2', [[1, 2], [3, 4]])
each number is put in their own separate cell as wanted. Is that the format I must use?
How may I resolve that issue? It is like my data needs to be sent JSON readable but cannot be a string otherwise it is interpreted as a single argument!
Any help would be very much appreciated.