Search code examples
pythongspread

Question of difference between append_row and append_rows


What is the difference between append_row and append_rows?

In append_row, worksheet.append_row (['test', 'test2']) works

At append_rows, Worksheet.append_rows(['test', 'test2']) is not working.

But

test = ["test1", "test2", "test3"]
val = worksheet.append_rows ([test])

is activated.

What's the difference between the two? It would be nice if there was an example for explanation.


Solution

  • When I saw the document of gspread, append_row appends a row to the sheet. Ref On the other hand, append_rows appends multiple rows to the sheet. Ref

    Sample script:

    append_row

    In this case, one row is appended. So, the 1-dimensional array is used as follows.

    worksheet.append_row(["test1", "test2"])
    

    append_rows

    In this case, multiple rows are appended. So, the 2-dimensional array is used as follows.

    worksheet.append_rows([["test1", "test2"], ["test3", "test4"]])
    

    Note:

    • As an additional information, when I saw the script of gspread, it seems that when append_row is run, the value is used with append_rows method. Ref So, it seems that the endpoint of Sheets API is the same between append_row and append_rows.

    References: