Search code examples
python-3.xpygsheets

Batch cells update with pygsheets


How can I update spreadsheet range with a list of values? For example if I have range A1:C7 and I want 1, 2, 3, 4, ... 21 values in cells. I can't even get a cell list with sheet.range function.

cell_list = sh.range('A1:C7', returnas='cells')

cause it does not return cell object if spreadsheet has empty cells.


Solution

  • To update a range of cells you can use a 2d list

    wks.update_cells('A2:C7',[[1,2,3],[4,5,6],[7,8,9] ... etc  ]) 
    

    to get cell objects even if you have empty cells, use

    get_values('A1', 'C7', returnas='cells', include_all=True)
    

    sheet.range currently dosen't return the exact rectangle specified (sticking to the api v4). Try raising an issue in github to get it fixed.