In the How to do it… section, in step 1 we import the openpyxl module and create a new Excel file. In step 2, we add the data to the first sheet. Step 3 is also a preparation step to define the colors to be used. The colors are defined in hex format, which is common in the web design world.
In step 4, we prepare the format to define the header. The header will have a different font (Tahoma), a bigger size (14pt), and it will be white on a blue background. To do this, we prepare a Font object with the font, size, and foreground color, and a PatternFill with the background color.
The loop after creating header_font and header_fill applies the font and fill to the proper cells.
In step 5, a border to the rows and an alternate background is applied. The border is defined with blue top and bottom and white left and right. The fill is created in a similar way to step 4, but in a light blue. The background is only applied to even rows.
The file is saved finally in step 6.