Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign multiple values in range

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?

like image 347
theta Avatar asked Nov 01 '22 08:11

theta


1 Answers

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
like image 84
Charlie Clark Avatar answered Nov 11 '22 16:11

Charlie Clark