从 python pptx 的 "Change Colors" 菜单中选择单色方案
Choose monochromatic scheme from "Change Colors" menu in python pptx
我找到了更改图表 样式 和逐点更改系列颜色的文档,但我没有找到任何关于从 "Change colors" 菜单。我特别想更改为单色配色方案,使用 PowerPoint 提供的颜色选项。
这很重要,因为我正在创建的文档将提供给不了解后端构建方式的人 — 他们只想操作数据,因此最好使用灵活的颜色。
我猜这需要直接更改 XML?
应用第一个(蓝色)单色样式后,这些行将添加到 XML。
<p:extLst><p:ext uri="{D42A27DB-BD31-4B8C-83A1-F6EECF244321}"><p14:modId xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="4058498100"/></p:ext></p:extLst>
但我不确定如何调用它们来编辑它们。我在这个过程的某个地方有文档吗?
是否类似于编辑 table 样式?
def table_formatting(table, shape, ic):
tbl = shape._element.graphic.graphicData.tbl
if ic == 'TABLE':
style_id = '{8EC20E35-A176-4012-BC5E-935CFFF8708E}'
else:
style_id = '{2D5ABB26-0587-4C30-8999-92F81FD0307C}'
tbl[0][-1].text = style_id
最简单的方法是创建一个新的空演示文稿,其中包含您希望每个生成的演示文稿都具有的特征,包括主题颜色和幻灯片布局等。一种方法是创建并保存一个空演示文稿在 PowerPoint 中,选择“新建演示文稿”屏幕上可用的 "built-in" themes/templates 之一后。
然后从 "template" PPTX 文件创建演示文稿:
prs = Presentation("my-template.pptx")
您可能想从 "template" PPTX 文件中删除所有幻灯片。您添加的任何新幻灯片都将附加在现有幻灯片之后。像这样调用 Presentation()
实质上是复制该命名演示文稿并将其用作起点。
调用 prs = Presentation()
做同样的事情,它只是使用 python-pptx
包中包含的默认模板演示。
我没有更改图表的调色板,这目前看来不可行,我正在使用与 PowerPoint 自动分配的相同 RGB 值创建首选颜色选择的字典,然后迭代每个点改变颜色。
def seriescolor_formatting(chart, intended_chart, catlen, slen):
if intended_chart == 'PIE':
for sc, series in enumerate(chart.series):
for i, point in enumerate(series.points):
point = chart.series[sc].points[i]
fill = point.format.fill
fill.solid()
fill.fore_color.rgb = v.brand_colors[catlen][i]
else:
for i, series in enumerate(chart.series):
fill = series.format.fill
fill.solid()
fill.fore_color.rgb = v.brand_colors[slen][i]
因为我是自学的,所以这可能比需要的更混乱。我计划在代码运行后对其进行重构,因此您认为可能有助于结构或方法的任何评论都将被阅读和赞赏。
我找到了一种更好的方法来自动获得我需要的效果,使用 Python pptx 的图表样式选项:
def createchart(chart_data, intendedchart):
graphic_frame = placeholder.insert_chart(v.charttypelist[intendedchart], chart_data)
chart = graphic_frame.chart
chart.chart_style = 3
我找到了更改图表 样式 和逐点更改系列颜色的文档,但我没有找到任何关于从 "Change colors" 菜单。我特别想更改为单色配色方案,使用 PowerPoint 提供的颜色选项。
这很重要,因为我正在创建的文档将提供给不了解后端构建方式的人 — 他们只想操作数据,因此最好使用灵活的颜色。
我猜这需要直接更改 XML?
应用第一个(蓝色)单色样式后,这些行将添加到 XML。
<p:extLst><p:ext uri="{D42A27DB-BD31-4B8C-83A1-F6EECF244321}"><p14:modId xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="4058498100"/></p:ext></p:extLst>
但我不确定如何调用它们来编辑它们。我在这个过程的某个地方有文档吗?
是否类似于编辑 table 样式?
def table_formatting(table, shape, ic):
tbl = shape._element.graphic.graphicData.tbl
if ic == 'TABLE':
style_id = '{8EC20E35-A176-4012-BC5E-935CFFF8708E}'
else:
style_id = '{2D5ABB26-0587-4C30-8999-92F81FD0307C}'
tbl[0][-1].text = style_id
最简单的方法是创建一个新的空演示文稿,其中包含您希望每个生成的演示文稿都具有的特征,包括主题颜色和幻灯片布局等。一种方法是创建并保存一个空演示文稿在 PowerPoint 中,选择“新建演示文稿”屏幕上可用的 "built-in" themes/templates 之一后。
然后从 "template" PPTX 文件创建演示文稿:
prs = Presentation("my-template.pptx")
您可能想从 "template" PPTX 文件中删除所有幻灯片。您添加的任何新幻灯片都将附加在现有幻灯片之后。像这样调用 Presentation()
实质上是复制该命名演示文稿并将其用作起点。
调用 prs = Presentation()
做同样的事情,它只是使用 python-pptx
包中包含的默认模板演示。
我没有更改图表的调色板,这目前看来不可行,我正在使用与 PowerPoint 自动分配的相同 RGB 值创建首选颜色选择的字典,然后迭代每个点改变颜色。
def seriescolor_formatting(chart, intended_chart, catlen, slen):
if intended_chart == 'PIE':
for sc, series in enumerate(chart.series):
for i, point in enumerate(series.points):
point = chart.series[sc].points[i]
fill = point.format.fill
fill.solid()
fill.fore_color.rgb = v.brand_colors[catlen][i]
else:
for i, series in enumerate(chart.series):
fill = series.format.fill
fill.solid()
fill.fore_color.rgb = v.brand_colors[slen][i]
因为我是自学的,所以这可能比需要的更混乱。我计划在代码运行后对其进行重构,因此您认为可能有助于结构或方法的任何评论都将被阅读和赞赏。
我找到了一种更好的方法来自动获得我需要的效果,使用 Python pptx 的图表样式选项:
def createchart(chart_data, intendedchart):
graphic_frame = placeholder.insert_chart(v.charttypelist[intendedchart], chart_data)
chart = graphic_frame.chart
chart.chart_style = 3