4 Examples to Make Excel Text Bold, Italic by openpyxl

In this tutorial, we will show you examples of making text bold in Excel cells, rows and columns by using openpyxl library.

How to make text bold, italic, strikethrough, and underlines using openpyxl

In this tutorial, we will show you examples of making text bold in Excel cells, rows, and columns by using openpyxl library.

For our examples, we will use the following sample sheet:

Excel-bold-italic-sample

Steps to style text bold, italic, and strikethrough sheet cells

Step 1

Load the required libraries:

Step 2

Load workbook & specify active sheet:

Step 3

Apply Style:

Step 4

Save the Workbook:

wb_style.save(“test_Excel.xlsx”)

Complete code and result sheet

Now let us combine all the above code in addition to making text italic and strikethrough and see the result sheet. Our target is to make text bold for C5 cell, italic for C6, and strikethrough for C7 cell:

Python Program to make text bold, italic, strikethrough

Result:

Excel-Style-Bold

Making whole row bold, italic, strikethrough, and underline example

In this example, we make 4th row bold, 5th row italic, 6th row strikethrough, and 7th row underline by using openpyxl library. Have a look at code and compare the sheet before and after code execution:

The code:

Result:

Excel-italic-strike-un

You may notice the highlighted rows number 4,5,6, and 7.

Applying all styles at one line example

In the example below, we applied bold, italic, underline and strikethrough in one line of code to four rows:

The code:

Result:

Excel-bold-italic-rows

Applying the above style to the column example

Similarly, you may apply the bold, italic etc. styles to columns by using iter_cols function. In the example below, we changed the font of columns number 2 and 3 and applied:

  • Bold
  • Italic
  • Underlined
  • strikethrough

The code:

Result:

Excel-bold-italic-colu