当前位置: 首页>>代码示例>>Python>>正文


Python shared.RGBColor方法代码示例

本文整理汇总了Python中docx.shared.RGBColor方法的典型用法代码示例。如果您正苦于以下问题:Python shared.RGBColor方法的具体用法?Python shared.RGBColor怎么用?Python shared.RGBColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docx.shared的用法示例。


在下文中一共展示了shared.RGBColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hex_to_rgb

# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import RGBColor [as 别名]
def hex_to_rgb(hex_color: str):
    """
    Convert a hex color string into an RGBColor object (used in python-elements)
    """
    hex_color = hex_color.lstrip('#')
    return RGBColor(*[int(hex_color[i:i + 2], 16) for i in (0, 2, 4)]) 
开发者ID:demisto,项目名称:dockerfiles,代码行数:8,代码来源:colors.py

示例2: create_psmdocx

# 需要导入模块: from docx import shared [as 别名]
# 或者: from docx.shared import RGBColor [as 别名]
def create_psmdocx(self, l, title, docxname):
        '''
        :param l list 一组题库
        :param title str 页面标题
        :param docxname  str 题库保存文件名
        :return: none
        '''
        if (title == ''):
            page_title = '小学生口算题'
        else:
            page_title = title
        p_docx = Document()  # 创建一个docx文档
        p_docx.styles['Normal'].font.name = u'Times'  # 可换成word里面任意字体
        p = p_docx.add_paragraph()
        p.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER  # 段落文字居中设置
        run = p.add_run(page_title)
        run.font.color.rgb = RGBColor(54, 0, 0)  # 颜色设置,这里是用RGB颜色
        run.font.size = Pt(self.p_title_size)  # 字体大小设置,和word里面的字号相对应

        sp = p_docx.add_paragraph()
        sp.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER  # 段落文字居中设置
        srun = sp.add_run(self.p_subtitle)
        srun.font.color.rgb = RGBColor(54, 0, 0)  # 颜色设置,这里是用RGB颜色
        srun.font.size = Pt(self.p_subtitle_size)  # 字体大小设置,和word里面的字号相对应

        # 判断需要用到的行数
        if (len(l) % self.p_column):
            rs = len(l) // self.p_column + 2
        else:
            rs = len(l) // self.p_column +1

        # print(rs)

        # 将口算题添加到docx表格中
        k = 0  # 计数器
        table = p_docx.add_table(rows=rs, cols=self.p_column)

        for i in range(rs):
            if i >0:
                row_cells = table.rows[i].cells
                for j in range(self.p_column):
                    if (k > len(l) - 1):
                        break
                    else:
                        row_cells[j].text = l[k]
                        k = k + 1
        table.style.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
        table.style.font.color.rgb = RGBColor(54, 0, 0)  # 颜色设置,这里是用RGB颜色
        table.style.font.size = Pt(self.p_content_siae)  # 字体大小设置,和word里面的字号相对应
        p_docx.save('{}.docx'.format(docxname))  # 输出docx 
开发者ID:bosichong,项目名称:PrimarySchoolMathematics,代码行数:52,代码来源:PrintPreview.py


注:本文中的docx.shared.RGBColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。