Skip to main content
 首页 » 编程设计

python之如何在 python-pptx 中为文本添加阴影

2024年10月24日22cyq1162

我正在做一个项目,我必须使用 python-pptx 创建一个 PowerPoint。我需要添加带有阴影的文本,使其看起来像这样:

如何在 python-pptx 中使用阴影格式化文本?

这是我使用的代码:

from pptx import Presentation 
from pptx.util import Inches, Pt 
from pptx.enum.shapes import MSO_SHAPE 
from pptx.dml.color import RGBColor 
from pptx.enum.dml import MSO_THEME_COLOR 
Temppath ="C:/Rept/Template/Template16.pptx" 
prs= Presentation(Temppath) 
slides =prs.slides[12] 
shapes=slides.shapes 
Month= "October" 
premont="Septmeber" 
 
for shape in shapes: 
    if shape.has_text_frame: 
       Text_frame=shape.text_frame 
       text=Text_frame.text 
       text= text.split(" ") 
       if "PrevMonth" in text: 
            strText=" ".join(text) 
            strText = strText.replace("PrevMonth",premont) 
            print(strText) 
            p=Text_frame.paragraphs[0] 
            p.clear() 
            run = p.add_run() 
            run.text= strText 
            font= run.font 
            font.color.theme_color = MSO_THEME_COLOR.DARK_2 
            #font.color.rbg=RGBColor(87,24,24) 
 
 
 
prs.save('test3.pptx') 

请您参考如下方法:

从 0.6.7 版本开始,python-pptx 还没有控制文本阴影的 API。

您可以在此处查看项目的 GitHub 问题列表上的功能请求并添加评论(可能 +1):https://github.com/scanny/python-pptx/issues/130