Reputation: 14690
In my application I have a bunch of cells not in range. Currently I am updating them one by one but it takes a lot of time. I would like to update them in batch by making just one call.
I looked at a few other SO threads such as this, but in my case the cells are not in range.
To simplify here is an example of what I am trying to achieve:
worksheet.update_acell("A1", "test1")
worksheet.update_acell("C5", "test2")
Is it possible to update cells not in range in one call?
Upvotes: 1
Views: 2606
Reputation: 21
Burnhash is correct in that there is no way to get a Cell without requesting it. However, I was able to acheive desired behaviour with a dummy class:
class Cell:
def __init__(self, c, r, v):
self.col = c
self.row = r
self.value = v
cell1 = Cell(1, 1, 'value1') # A1
cell2 = Cell(2, 1, 'value2') # B1
wk.update_cells([cell1, cell2])
Upvotes: 1
Reputation: 3321
Yes, it's possible. You can use Worksheet.update_cells
method for this.
The argument of the method is a list of Cell
objects and it doesn't matter where this list comes from. You can get it from range
method or create the list yourself:
a1 = worksheet.acell('A1')
c5 = worksheet.acell('C5')
a1.value = 'Hello'
c5.value = 'World'
wk.update_cells([a1, c5])
This updates multiple cells in one call.
Upvotes: 2