Python OpenPyXL Set Font Size of Excel Cells

In this Python openpyxl tutorial we learn how to set font size for Excel cells using the openpyxl package.

How to install the openpyxl package

To install the openpyxl package using the command below.

pip install openpyxl

How to set font size 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 cell.

ws['A1'] = 'Tori Code'

Create a new Font object with font size 100.

font = Font(size=100)

Assign the font to A1 cell.

ws['A1'].font = font

Then save the Workbook as font_size.xlsx file.

wb.save('font_size.xlsx')

The complete Python program as below.

font_size.py

from openpyxl import Workbook
from openpyxl.styles import Font

wb = Workbook()
ws = wb.active

ws['A1'] = 'Tori Code'

font = Font(size=100)

ws['A1'].font = font

wb.save('font_size.xlsx')

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

Python openpyxl Set Font Size of Excel Cells

Happy Coding 😊