- Loading a workbook:
wb = load_workbook(filename = pruned_bugs_path, data_only=False)
sheet = wb['sheetname']
Apart from filename, there are some parameters such as data_only, read_only, keep_vba, data_only, keep_links.
- Creating a table:
# Creating a table for the outstanding bugs
from openpyxl.worksheet.table import Table, TableStyleInfo
table_range = f'A4:T'+ str(sheet.max_row + 3)
tab = Table(displayName='outstandingbugs', ref=table_range)
style = TableStyleInfo(name='TableStyleLight12', showFirstColumn=False, showLastColumn=False, showRowStripes=True, showColumnStripes=True)
tab.tableStyleInfo = style
report_sheet_outstanding_bugs.add_table(tab)
- Writing everything in a cell in red color.
cell = header['C5']
cell.font = Font(name='Arial', color=Color('FF0000'), bold=True, size=14) # Use RGB hex code for color
cell.value = current_version
- Conditional formatting
red_fill = PatternFill(bgColor="FF0000")
dxf = DifferentialStyle(font=black_text, fill=red_fill)
rule = Rule(text="S1-System stop", type='containsText', operator="containsText", dxf=dxf)
rule.formula = ['NOT(ISERROR(SEARCH("S1-System stop",B5)))']
report_sheet_outstanding_bugs.conditional_formatting.add('B5:B1000', rule)
high_visibility_bugs.conditional_formatting.add('B5:B1000', rule)