Colorizing tabs in openpyxl

We have a situation where we want to colorize tabs for worksheets using openpyxl. Is there any way to do this in the library? Or did anyone find a way to make this external to the library (i.e., an Extension or something similar)?

+5
source share
2 answers

You can set the tab color to 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()

Colored tabs in Excel worksheet using Python

+3
source

You can color tabs with openpyxl using the RRGGBB color code for the 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')

enter image description here

+4
source

All Articles