We have a situation where we want to color the tabs for the worksheets using openpyxl. Is there a way to do this within the library? Or, has anyone found a way to do this external to the library (i.e. by extension or something similar)?
You can color the tabs with openpyxl by using RRGGBB color code for sheet_properties.tabColor property:
from openpyxl import Workbook
wb = Workbook()
ws = wb.create_sheet('My_Color_Title')
ws.sheet_properties.tabColor = 'FFFF00'
wb.save('My_book_with_Yellow_Tab.xlsx')
You can set the tab color in a new Excel file using the XlsxWriter Python module. Here is an example:
from xlsxwriter.workbook import Workbook
workbook = Workbook('tab_colors.xlsx')
# Set up some worksheets.
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet()
worksheet3 = workbook.add_worksheet()
worksheet4 = workbook.add_worksheet()
# Set tab colours
worksheet1.set_tab_color('red')
worksheet2.set_tab_color('green')
worksheet3.set_tab_color('#FF9900') # Orange
# worksheet4 will have the default colour.
workbook.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With