Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write data to excel using Openpyxl

I have a list mv = [‘200’, ‘200’, ‘4000’, ‘400’, ‘600’, ‘700’] that I want to write to cells F14 to F19 in an existing excel table. How do I use openxl to accomplish this with the list? so Far I have

from openpyxl import Workbook, load_workbook

wb = load_workbook('test.xlsx')
ws = wb['12Channel']


for row in range(14,19):
                for col in range(6):
                    ws.append(mv)

The data is not being appended.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here is a proposition with openpyxl based on your code :

from openpyxl import load_workbook

wb = load_workbook('test.xlsx')
ws = wb['12Channel']

mv = ['200', '200', '4000', '400', '600', '700'] 

for pos, val in enumerate(mv):
    ws.cell(row=pos+14, column=6).value = val # 6 is the position col F
        
wb.save('test.xlsx')  

# Output :

enter image description here

NB: Make sure to keep always a backup/copy of your original Excel file before running any kind of python/openpyxl’s script.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading