Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top