Ideally, I would like to pass the Alpha to the green color for example
"4D228b22" but this gives an error upon opening.
I have tried creating a separate ColorChoice object as well but I cannot pass a modified color object to it.
This works for setting a green color. Other example after this code.
from openpyxl import Workbook
from openpyxl.chart import AreaChart, Reference
import datetime, random
output_filename = "OpenPyXL_Area_Charts.xlsx"
output_wb = Workbook()
output_ws = output_wb.active
# Create some dates
dates = [datetime.date(2020, x, 1) for x in range(1,10,2)]
# Create som values for first and seconds bars
bars1 = [random.randint(10,50) for _ in range(5)]
bars2 = [random.randint(10,50) for _ in range(5)]
# Write the values to the sheet
for row in zip(dates,bars1, bars2):
output_ws.append(row)
#Create the References
date_series = Reference(output_ws, min_col=1, min_row=1, max_col=1, max_row=5)
area1_series = Reference(output_ws, min_col=2, min_row=1, max_col=2, max_row=5)
area2_series = Reference(output_ws, min_col=3, min_row=1, max_col=3, max_row=5)
# Add Area Chart
area_chart = AreaChart()
area_chart.add_data(area1_series)
# Set the color of area1_series to green
green_color = "228b22"
a1_series = area_chart.series[0]
a1_series.graphicalProperties.line.solidFill = green_color
a1_series.graphicalProperties.solidFill = green_color
area_chart.add_data(area2_series)
area_chart.set_categories(date_series)
area_chart.title = "Bar Chart colors"
area_chart.x_axis.title = "Dates"
area_chart.y_axis.title = "Values"
output_ws.add_chart(area_chart, "A16")
output_wb.save(output_filename)
################################
But I would like to do like this
# Create green color
green_color = Color("228b22")
green_color.rgb =
"4D228b22"
a1_series = area_chart.series[0]
a1_series.graphicalProperties.line.solidFill = ColorChoice(srgbClr=green_color)
a1_series.graphicalProperties.solidFill = ColorChoice(srgbClr=green_color)
srgbClr needs to be passed as a string, but then I cannot pass a color with Alpha channel to change transparency.