Python Forum
Need to identify sheet color in excel workbook - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need to identify sheet color in excel workbook (/thread-24432.html)



Need to identify sheet color in excel workbook - chewy1418 - Feb-13-2020

Hi all,

I have a given excel workbook that has multiple sheets. Some of these sheets have a colored background to them. Unfortunately, I am having trouble attaching a screenshot of this but I basically need to identify sheets that have a blue background.

I know that openpyxl and xlrd have the ability to load workbooks, get the sheet names and then loop through them. Does either of these modules have the ability to grab the sheet color or is there another library that can handle my intended scenario?

Below is some code I have been playing around with ..

# from openpyxl import load_workbook

# workbook = load_workbook(filename='TestRateFile.xlsx', read_only=True)
# sheets = workbook.sheetnames

# for s in sheets:
    # print(s)

import xlrd
loc = ('InXLS.xls')

wb = xlrd.open_workbook(loc, formatting_info=True)
sheets = wb.sheet_names()

for index, sh in enumerate(sheets):
    print(sh)

Below is the snippet I took of the workbook sheets

https://imgur.com/a/8Kdha8P


RE: Need to identify sheet color in excel workbook - Larz60+ - Feb-13-2020

only a guess, but named_styes? https://openpyxl.readthedocs.io/en/latest/api/openpyxl.workbook.workbook.html#openpyxl.workbook.workbook.Workbook.named_styles


RE: Need to identify sheet color in excel workbook - chewy1418 - Feb-14-2020

Unfortunately, the named_styles approach did not work :(