Josh
Josh

Reputation: 1

Pygsheets append_table issue

I am at a loss. This is the final part of the script I am writing, and I can not get the data in the list 'Rows_Cleaned' to append to my spreadsheet. Now, the code works until the final line. I can print out the list 'Rows_Cleaned', but it will not append beyond the first row.

import pygsheets
json = path to json
spreadsht = json.open("Name of Spreadsheet")
gsheet = spreadsht.worksheet("title", tab name)
Rows_Cleaned = []

for a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t in  zip(Site_ID,Site_Name,Location,ID,Last_Name,First_Name,Middle_Name,Staff_Type,Grade,Homeroom,Product,Tag,Charge_Type,Description,Charge_Notes,Issue_Date,Charge_Amount,Amount_Paid,Amount_Due,Satisfied_Date): 
#zipping a number of lists I am generating

Rows = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t]

if start_date <= p <= end_date: #Date check works
    Rows_Cleaned.append(Rows)

for data in Rows_Cleaned:
    gsheet.append_table(data, start='A2', end=None, dimension='ROWS', overwrite=False)

I have spent a few hours testing the rest of the code, making sure that the list comes out correctly, and that it prints, and even the .update_row() function works with Rows_Cleaned.

When I run this code, it appends the first index of the 'Rows_Cleaned' no problem, but when it attempts to advance to the second index, it spits out a "KeyError: 'tableRange'" error. I am not sure what I am doing wrong in this case. I would like for it to output each index of the list 'Rows_Cleaned' on a separate row.

I have also attempted to append the spreadsheet with a simplified 2D list, and it gives the same error (Test_Data = [[123, 456,789],['test',123,'testing']]).

The Data I'm actually working with inside a list looks something like this:

(['="Number"', 'Name, 'Student', '="Number"', 'Name', 'Name', 'Name', None, '9', '="B228"', 'HP CHROMEBOOK 11MK G9 MODEL #349Y8UT', '="Number"', '23-24 Lost Device', None, None, '10/27/2023 9:49:26 AM', '200.0000', '200.0000', '0.0000', '10/27/2023 9:49:26 AM'], ['="128"', 'Name', 'Student', '="Number"', 'Name', 'Name', 'Name', None, '3', '="218"', 'HP CHROMEBOOK 11MK G9 MODEL #349Y8UT', '="Number"', '23-24 Chromebook Adapter', None, '7005758 - TESTING TOMORROW: Lost Chromebook charger', '10/23/2023 10:35:22 AM', '20.0000', '0.0000', '0.0000', '10/23/2023 10:35:22 AM'])

The fact that it starts to work and then errors out is driving me crazy. Thank you for any input given.

Also, the documentation for pygsheets is here

Also, also, an example of someone using this in the same way I am trying to use it

Upvotes: 0

Views: 367

Answers (1)

Josh
Josh

Reputation: 1

After another hour or so more researching I solved it:

gsheet.update_values(crange='A2',values=Rows_Cleaned,majordim='ROWS')

Upvotes: 0

Related Questions