Home > Back-end >  Writing data to google sheets in a single column tries to write data to a column outside the determi
Writing data to google sheets in a single column tries to write data to a column outside the determi

Time:03-01

I have a google sheet in which I would like to add data to a certain range:

enter image description here

And to write the data I use:

ws = sheet.worksheet('test_sheet')
ws.update("HG3:HG5", [["test_1", "test_2", "test_3"]])

But I can an error:

APIError: {'code': 400, 'message': 'Requested writing within range [test_sheet!HG3:HG5], but tried writing to column [HH]', 'status': 'INVALID_ARGUMENT'}

Why does it try to write to column HH if the range is clearly HG3:HG5? I do have a range that contains 3 cells and values inside ws.update also has 3 values. I tried using single brackets for ["test_1", "test_2", "test_3"] but that produces another error.

Where is my mistake? My goal is to be able to write values to a single column's range as in the image the values would become "test_1", "test_2", "test_3".

CodePudding user response:

  • The notation [["test_1", "test_2", "test_3"]] writes into 3 columns of the same row

  • To write into 3 rows of the same column, the notaiton should be [["test_1"], ["test_2"], ["test_3"]]

See Writing to a single range.

  • Related