Search code examples
pythongoogle-sheetsgoogle-sheets-apigspread

Write rows bottom in Google Sheet from Python


I am trying to write rows with python in one google sheet. I found function .insert_row() with that new rows are written in the top of my google sheet. How can I write it in the bottom? Any ideas?

That is how I am trying it now:

sheet.insert_rows(df_test.values.tolist())

Solution

  • I believe your goal is as follows.

    • In your situation, for example, the sheet has 1000 rows. The rows which are not empty are from 1st row to row 10.
    • You want to put the values from the next empty row that it's row 11. This is the 1st empty row.
    • From your script of sheet.insert_rows(df_test.values.tolist()), you want to achieve this using gspread for python.

    In this case, how about the following modification? In this modification, append_rows method is used instead of insert_rows.

    From:

    sheet.insert_rows(df_test.values.tolist())
    

    To:

    sheet.append_rows(df_test.values.tolist(), value_input_option="USER_ENTERED")
    

    Reference: