Getting Excel cell background themed color as hex with openpyxl

前端 未结 2 683
刺人心
刺人心 2021-01-16 01:41

I\'m reading *xlsx files with openpyxl python library, and within other data I want to get information on cells background color.

This code I was using normally, w

2条回答
  •  北海茫月
    2021-01-16 02:03

    After hours of googling finally found the solution - proposed idea to add converting between theme + tint to RGB in openpyxl. Importing their set of color converting functions, I can reduce my solution to the next steps:

    wb = load_workbook(filename, data_only=True)
    theme = cell.fill.start_color.theme
    tint = cell.fill.start_color.tint
    color = theme_and_tint_to_rgb(wb, theme, tint)
    

提交回复
热议问题