Python OpenPyXL Font Italic for Excel Cells

In this Python OpenPyXL tutorial we learn how to set the font italic style for Excel cells using the OpenPyXL package Font class.

How to install the OpenPyXL package

To install the OpenPyXL package using the command below.

pip install openpyxl

How to set font italic for the Excel cells

Import the Workbook and Font from the OpenPyXL package.

from openpyxl import Workbook
from openpyxl.styles import Font

Create a new Workbook object.

wb = Workbook()

Get the default active Worksheet object.

ws = wb.active

Assign value for A1 and A2 cells.

ws['A1'] = 'Tori Code'
ws['A2'] = 'Tori Code'

Create a new Font object with italic is True.

font = Font(italic=True)

Assign the font to A1 cell.

ws['A1'].font = font

Then save the Workbook as font_italic.xlsx file.

wb.save('font_italic.xlsx')

The complete Python program as below.

font_italic.py

from openpyxl import Workbook
from openpyxl.styles import Font

wb = Workbook()
ws = wb.active

ws['A1'] = 'Tori Code'
ws['A2'] = 'Tori Code'

font = Font(italic=True)
ws['A1'].font = font

wb.save('font_italic.xlsx')

Execute the above Python program we will get the Excel file font_italic.xlsx as below screenshot.

Python OpenPyXL Font Italic for Excel Cells

Happy Coding 😊