update_cells no longer supports non-contiguous cells (overwrites unlisted cells within the range)
See original GitHub issueThis appears to be a regression in the gpsread use of the v4 API (was previously working: see #177)
Environment info
Operating System: Windows / Linux Python version: 2.7.14 gspread version: 2.1.1
Steps to reproduce
- Make a list of cells that are non-contiguous, e.g. [<Cell R7C2 ‘2018’>, <Cell R20C2 ‘2004’>]
- Call update_cells, passing the list
- Cells R7C2 through R20C2 inclusive get updated, with only R7C2 and R20C2 having values, R8-R19C2 all get zeroed out.
Stack trace or other output that would be helpful
Compare update_cells implementation in /v4/models.py
with models.py
>>> worksheet.range('B7:B20')
[<Cell R7C2 ''>, <Cell R8C2 ''>, <Cell R9C2 u'2013'>, <Cell R10C2 u'2013'>, <Cell R11C2 u'2015'>, <Cell R12C2 u'2015'>, <Cell R13C2 ''>, <Cell R14C2 u'2017'>, <Cell R15C2 u'2015'>, <Cell R16C2 u'2017'>, <Cell R17C2 u'2016'>, <Cell R18C2 u'2014'>, <Cell R19C2 u'2012'>, <Cell R20C2 ''>]
>>> cells = worksheet.range('B7:B20')
>>> other_cells = []
>>> other_cells.append(cells[0])
>>> other_cells.append(cells[len(cells)-1])
>>> other_cells
[<Cell R7C2 ''>, <Cell R20C2 ''>]
>>> other_cells[0].value = "test"
>>> other_cells[1].value = "testing"
>>> len(other_cells)
2
>>> worksheet.update_cells(other_cells)
{u'spreadsheetId': u'**removed**', u'updatedRange': u'Collection!B7:B20', u'updatedCells': 14, u'updatedRows': 14, u'updatedColumns': 1}
>>> worksheet.range('B7:B20')
[<Cell R7C2 u'test'>, <Cell R8C2 ''>, <Cell R9C2 ''>, <Cell R10C2 ''>, <Cell R11C2 ''>, <Cell R12C2 ''>, <Cell R13C2 ''>, <Cell R14C2 ''>, <Cell R15C2 ''>, <Cell R16C2 ''>, <Cell R17C2 ''>, <Cell R18C2 ''>, <Cell R19C2 ''>, <Cell R20C2 u'testing'>]
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
google sheets api select non-adjacent cells - Stack Overflow
What would be the range for selecting multiple non-adjacent cells? I am trying to update cells that are non-adjacent from a sheet (A2...
Read more >How To Select Non Adjacent Cells In Excel & Google Sheets
Click on the cell. Press the Control key on the keyboard. Keep holding it down while you are selecting cells.
Read more >2-7: Select Non-Contiguous (Non-Adjacent) Cell Ranges
Non-contiguous ( non adjacent ) cell ranges are blocks of cells that are not next to each other. You'll learn how to select...
Read more >How to Select Non-contiguous Ranges of Cells in Excel 2016
You can select different ranges of cells in two ways, ... You can change the formatting for all non-contiguous cells selected at the...
Read more >Fit to Element Range Dialog - Bentley - Product Documentation
Lets you type a cell name or regular expression to identify one or more cells. This limits the search for specified elements to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@CianH thank you for reporting the issue. It was fixed in #553 and released in version 3.0.1 on pypi. Please upgrade the library and check.
@AlexRiina thank you very much for the hint and comments. @ADraginda thank you again for the pull request with the fix.
I’m closing this issue now.
@CianH Using @AlexRiina 's suggestion, I verified that setting to None does work. I’ll be submitting a PR, but in the interim you can workaround the issue by setting the
.value
for every cell to None before doing your actual value setting. If you do that, then only your changes will be applies.