I have a large excel data file, with gapped rows at the top, a mix of data types and various blank cells. I want to pattern fill blank cells based on a value in one cell in the row and the column heading being found in a list.
I have:
I would like:
So far I have been able to access each cell and pattern fill on the basis on the cell contents (a random string):
import openpyxl
from openpyxl.styles.colors import Color
from openpyxl.styles import PatternFill
wbInPanel = openpyxl.load_workbook("file\path.xlsx")
shInPanel = wbInPanel['SheetName']
c = Color(indexed=55)
fmtFillPattern = PatternFill(start_color=c,fill_type='lightTrellis')
for row in shInPanel.iter_rows(shInPanel.min_row,shInPanel.max_row):
for cell in row:
if cell.value == '*?!*':
cell.fill = fmtFillPattern
cell.value = ''
wbInPanel.save("file\path.xlsx")
wbInPanel.close()
I also have my list of headings:
headingsList = ['Heading3','Heading5']
I know I now need to include a couple of if loops, one for if Heading2 == 'A', which needs to be changeable as I may also wish to search if Heading4 > 5, and one for if cell is in col with heading in list.
- Where/How do I put the if loops in?
- How do I search the heading list whilst I am in the cell in the loop?

