In VBA I can assign array to range of cells, so that every cell in range gets corresponding value from the array:
Range("A1:D1").Value = Array(1, 2, 3, 4)
I was trying to do the same with openpyxl:
import openpyxl
wb = openpyxl.Workbook()
ws = wb.worksheets[0]
ws.range['A1:D1'].value = [1, 2, 3, 4]
but without success.
Is there a way to do range assignment with openpyxl without iterating every cell?
No, it is not possible, a range in openpyxl is just a range of cells but looping is easy enough (openpyxl 1.8 syntax)
for v,c in zip([1, 2, 3, 4], ws['A1':'D1']):
c.value = v
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With