问题描述
我有一个PowerPoint演示文稿,其中有一个图表,我想在该图表中更改数据标签中一个字符的颜色。
ChartObject.SeriesCollection(SeriesCounter).Points(PointCounter).DataLabel.Format.TextFrame2.TextRange.Characters(1,2).Font.Fill.ForeColor.RGB = ColourSigLower
但是,当我尝试通过Python 3 COM进行相同操作时,出现以下错误
com_error: (-2147352559,'Does not support a collection.',None,None)
这是我尝试执行的操作的完整代码段:
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()
您有想法我该怎么做? 我尝试过早绑定和后期绑定,但无济于事。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)