关于#python#的问题,请各位专家解答!

#请问各位大佬python修改word图注该怎么实现呢
还有它的字体应该如何修改呢

https://blog.csdn.net/GISuuser/article/details/125619199
仿照循环遍历思路,修改下text_frame属性即可。

for shape in doc.inline_shapes:
    if shape.has_text_frame:
        text_frame = shape.text_frame
        text_frame.text = "修改后图注"

        for paragraph in text_frame.paragraphs:
            for run in paragraph.runs:
                font = run.font
                font.name = "Arial"  
                font.size = Pt(22) 




# 获取所有图注
captions = doc.inline_shapes

# 遍历所有图注
for caption in captions:
    # 获取图注的文字
    caption_text = caption.text_frame.text
    # 修改图注文字
    caption.text_frame.text = '新的图注文字'

    # 获取图注的字体
    caption_font = caption.text_frame.paragraphs[0].runs[0].font
    # 修改图注字体大小
    caption_font.size = Pt(12)
    # 修改图注字体颜色
    caption_font.color.rgb = RGBColor(255, 0, 0)  # 红色