本文整理匯總了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)])
示例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