需求把WORD中加粗的文字改变颜色,
使用了魔法指令,运行后出错,求解法~
# 使用此指令前,先安装必要的python库,使用以下命令
# pip install python-docx
from docx import Document
from docx.shared import RGBColor
from xbot import print
from typing import *
def change_bold_text_color(file_path, color):
"""
title: 修改加粗文字的颜色
description: 将Word文档中所有加粗的文字修改为指定的颜色
inputs:
- file_path (file): Word文档的文件路径,eg: "path/to/file.docx"
- color (str): 颜色的RGB值,eg: "FF0000"表示红色
outputs:
- None
"""
doc = Document(file_path)
for paragraph in doc.paragraphs:
for run in paragraph.runs:
if run.bold:
run.font.color.rgb = RGBColor.from_string(color)
doc.save(file_path)