Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.4k views
in Technique[技术] by (71.8m points)

python - Assign List to Iterated Columns - OpenPYXL

I want to assign the below list to a range of cells using OpenPYXL.

quarters = ['Q1', 'Q2', 'Q3', 'Q4']

I used the below to assign one value over a range, which worked fine.

for col in cpcp.iter_cols(min_row=2, max_row=3, min_col=23, max_col=55):
    for cell in col:
        cell.value = 'P'

However, I tried the below code with a List...

quarters = ['Q1', 'Q2', 'Q3', 'Q4']
for col in cpcp.iter_cols(min_row=4, max_row=4, min_col=23, max_col=54):
    for col, value in enumerate(quarters):
        cell.value = quarters

I'm getting the below error:

ValueError: Cannot convert ['Q1', 'Q2', 'Q3', 'Q4'] to Excel

Below is a snippet of what I'm trying to acheive:

enter image description here

Thanks for your help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...