Skip to content

font.fill and font.color currently do the same thing (they both change the font colour) #537

@OD1995

Description

@OD1995

My code is as follows:

import pandas as pd
pd.options.mode.chained_assignment = None
import pptx
from pptx.util import Cm
from pptx.dml.color import RGBColor
from pptx.enum.chart import XL_CHART_TYPE
from pptx.chart.data import ChartData


## Select path from which the deck will be imported
path_import = r"XXXX.pptx"
## Select layout, layout number can be worked out from the options when you add a new slide
SLD_LAYOUT_TITLE_AND_CONTENT = 6 #Empty template
## Create instance of Presentation
prs = pptx.Presentation(path_import)
## Add slide with the pre-chosen format
slide_layout = prs.slide_layouts[SLD_LAYOUT_TITLE_AND_CONTENT]
slide = prs.slides.add_slide(slide_layout)
## Generate data
chart_data1 = ChartData()
chart_data1.categories = [f"TM {i}" for i in range(1,21)]
chart_data1.add_series('Series 1', [x for x in range(20)])
## Add chart
graphic_frame1 = slide.shapes.add_chart(chart_type=XL_CHART_TYPE.COLUMN_CLUSTERED,
                                x=Cm(0.75),
                                y=Cm(4.71),
                                cx=Cm(32.12),
                                cy=Cm(10.76),
                                chart_data=chart_data1)
## Add data labels to the chart
graphic_frame1.chart.plots[0].has_data_labels = True
## (Attempt to) add a turquoise fill to the data labels
graphic_frame1.chart.plots[0].data_labels.font.fill.solid()
graphic_frame1.chart.plots[0].data_labels.font.fill.fore_color.rgb = RGBColor(36,210,254)
## Change font colour to orange
graphic_frame1.chart.plots[0].data_labels.font.color.rgb = RGBColor(249,165,41)
## Save deck to path
path_export = r"YYYY.pptx"
prs.save(path_export)

This produces a slide with a chart that has orange font (as expected) but no turquoise fill. By fill I mean the background fill of the labels.

I've discovered that if I comment out the graphic_frame1.chart.plots[0].data_labels.font.color.rgb = RGBColor(249,165,41) line, the font colour becomes turquoise, which I don't think is the intended outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions