Powerpoint changing one character's color in a chart's datalabel through COM in python

孤街浪徒 提交于 2020-12-13 02:57:45

问题


I have a PowerPoint presentation where I have a chart where I want to change one charcter's colour in a datalabel. Here is an example of what I want to achieve. The triangle to be coloured red 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!