Skip to content Skip to sidebar Skip to footer

How To Format Columns With Headers Using Openpyxl

I am trying to format certain columns in a date format. I am able to successfully change an individual cell's format using: date_style = Style(number_format='M/D/YYYY') ws['E7'].st

Solution 1:

I figured it out, although probably not the most elegant way:

date_style = Style(number_format="M/D/YYYY")
for col inrange(5,8,2):
    forrowinrange(2,100,1):
        ws.cell(row=row,column=col).style = date_style

I wanted columns 5 and 7 to have the date formatting. This did the trick, but of course if I have more than 100 rows, I'll have to raise that number.

Post a Comment for "How To Format Columns With Headers Using Openpyxl"