Python OpenPyXL Font Strike for Excel Cells
In this Python OpenPyXL tutorial we learn how to set the font strike 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 strike 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 strike is True.
font = Font(strike=True)
Assign the font to A1 cell.
ws['A1'].font = font
Then save the Workbook as font_strike.xlsx file.
wb.save('font_strike.xlsx')
The complete Python program as below.
font_strike.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(strike=True)
ws['A1'].font = font
wb.save('font_strike.xlsx')
Execute the above Python program we will get the Excel file font_strike.xlsx as below screenshot.
Happy Coding 😊