Assigning multiple values ​​in a range

In VBA, I can assign an array to a range of cells, so that each cell in the range gets the corresponding value from the array:

Range("A1:D1").Value = Array(1, 2, 3, 4)

I tried 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 using openpyxl without iterating over each cell?

+4
source share
1 answer

No, this is not possible, the range in openpyxl is just a range of cells, but the loop is quite simple (openpyxl 1.8 syntax)

for v,c in zip([1, 2, 3, 4], ws['A1':'D1']):
     c.value = v
+2
source

All Articles