[Python] In a Excel file how to find the background color of a cell using openpyxl (Python)

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    wb = openpyxl.load_workbook('file.xlsx',data_only=True)
    fs_count_row = fs.max_row
    fs_count_col = fs.max_column
    for a in range(1,fs_count_row):
    cell_color = fs.cell(column=1, row=a)
    bgColor = cell_color.fill.bgColor.index
    fgColor = cell_color.fill.fgColor.index`


    Tried using the above code. However, it works fine for some cells and give wrong output for some other cells. Can I know the reason why?

    Continue reading...

Compartilhe esta Página