I'm trying to use Excel's theme colors in a chart created by openpyxl. I want to have theme colors so that the entire workbook's colors can be updated when the user loads a new theme.
Openpyxl has functionality to color the series bars in a bar chart with rgb values as shown below.
import openpyxl
wb = openpyxl.load_workbook('myBook.xlsx')
ws = wb["chartSheet"]
chart = openpyxl.chart.BarChart()
chart.type = "col"
data = Reference(ws, min_col=2, min_row=1, max_row=7, max_col=3)
cats = Reference(ws, min_col=1, min_row=2, max_row=7)
chart.add_data(data, titles_from_data=True)
chart.set_categories(cats)
chart.series[0].graphicalProperties.solidFill = 'FFFF66'
ws.add_chart(chart, "B2")
For styling the fill color of a cell, there is an openpyxl.styles.colors.Color object that allows you to define colors in terms of a theme, like this: openpyxl.styles.colors.Color(theme=7)
However, the object that is used for bar chart styling is an openpyxl.drawing.colors object which only accepts rgb values.
It's definitely possible within the Excel application to style bars with a theme color. Theoretically, I could use some post-production script to edit the raw xml of the excel file after being saved, but that would be pretty inefficient.
Is there any way to accomplish this within openpyxl?