From the course: Advanced Hands-On Python: Working with Excel and Spreadsheet Data

Unlock the full course today

Join today to access over 24,600 courses taught by industry experts.

Applying conditional formatting

Applying conditional formatting

- [Instructor] One of the great features of Excel is the ability to apply conditional formatting to cell content based on certain conditions. This really helps identify specific data conditions when you have a large amount of data in a worksheet because it's much easier to process visual information. Openpyxl lets you add conditional formatting to your Excel data with some simple Python code. So for this example, we're going to use the FinancialSample Excel file and the data that's in the SalesData worksheet. Let's go ahead and open up our sample code. All right, so you can see here in my sample code, I've already got some code that loads the workbook and gets the SalesData worksheet. So first what we need to do is define some styles to represent the formats that will be applied by the conditions that we specify later. And we do this the same way that we do define styles as we saw earlier in the chapter, when we did the example on creating cell styles. So I'm going to define some…

Contents