问题
I have a PowerPoint presentation where I have a chart where I want to change one charcter's colour in a datalabel. In VBA I can do this with
ChartObject.SeriesCollection(SeriesCounter).Points(PointCounter).DataLabel.Format.TextFrame2.TextRange.Characters(1, 2).Font.Fill.ForeColor.RGB = ColourSigLower
However, when I try to do the same via Python 3 COM I get the following error
com_error: (-2147352559, 'Does not support a collection.', None, None)
Here is a full code snippet of what I try to do:
pythoncom.CoInitialize()
ppt_instance = win32com.client.dynamic.Dispatch('PowerPoint.Application')
#open the powerpoint presentation headless in background
read_only = True
has_title = False
window = False
myCompath=str(path.parent / 'Report' / 'test.pptx')
myCOMpath_output=str(path.parent / 'Report' / 'Output_test.pptx')
prsCOM = ppt_instance.Presentations.open(myCompath,has_title,window)
def RGB(R,G,B):
return B*256*256+G*256+R
chart_obj=prsCOM.Slides("BFDOT").Shapes("TOM").Chart
aaamy = chart_obj.FullSeriesCollection(1).Points(1).DataLabel.Text
chart_obj.FullSeriesCollection(1).Points(1).DataLabel.Format.TextFrame2.TextRange.Characters.Text= aaamy + " " + chr(9660)
###Below line is where it breaks
chart_obj.FullSeriesCollection(1).Points(1).DataLabel.Format.TextFrame2.TextRange.Characters(1,2).Font.Fill.ForeColor.RGB = RGB(245, 165, 150) #Here is where it breaks
prsCOM.SaveAs(myCOMpath_output)
prsCOM.Close
prsCOM.Application.Quit()
pythoncom.CoUninitialize()
Do you have ideas how can I accomplish this? I have tried early and late binding but doesn't help.
来源:https://stackoverflow.com/questions/64371361/powerpoint-changing-one-characters-color-in-a-charts-datalabel-through-com-in