I am trying to add conditional formatting (highlight cell containing pipe character) to Excel using openpyxl (2.5.4) in Python 2.7. I have tried with many variants of code as seen below. None of it worked. Can you point where is error?
import openpyxl
from openpyxl import formatting, styles, Workbook
wb = openpyxl.load_workbook('export.xlsx')
sheet = wb['all']
red_text = Font(color='9C0006')
red_fill = PatternFill(bgColor='FFC7CE')
Variant 1 - code
sheet.conditional_formatting.add('A1:E4', rule(type='containsText', operator='containsText', text='|', fill=red_fill, font=red_text))
Variant 1 - error
NameError: name 'rule' is not defined
Variant 2 - code
sheet.conditional_formatting.add('A1:E4', CellIsRule(type='containsText', operator='containsText', text='|', fill=red_fill, font=red_text))
Variant 2 - error
TypeError: CellIsRule() got an unexpected keyword argument 'type'
Variant 3 - code
sheet.conditional_formatting.add('A1:E4', formatting.rule.CellIsRule(type='containsText', operator='containsText', text='|', fill=red_fill, font=red_text))
Variant 3 - error
TypeError: CellIsRule() got an unexpected keyword argument 'type'
Variant 4 - code
sheet.conditional_formatting.add('A1:E4', formatting.rule.CellIsRule(operator='containsText', text='|', fill=red_fill, font=red_text))
Variant 4 - error
TypeError: CellIsRule() got an unexpected keyword argument 'text'