|
藝賽旗|做RPA生態(tài)先行者 RPA10.0全新首發(fā)免費(fèi)下載 點擊下載 藝賽旗-RPA機(jī)器人免費(fèi)下載|提供流程自動化解決方案?www.i-search.com.cn 引入會用到的庫 from docx import Document
from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Cm
from docx.shared import RGBColor表格樣式
設(shè)置表格列寬 & 行高'''
設(shè)置列寬
可以設(shè)置每個單元格的寬,同列單元格寬度相同,如果定義了不同的寬度將以最大值準(zhǔn)
'''
table.cell(0,0).width=Cm(10)
#設(shè)置行高
table.rows[0].height=Cm(2)表格數(shù)據(jù)寫入
表格文本格式設(shè)置#單個單元格設(shè)置
run.font.color.rgb = RGBColor(255, 0, 0) # 顏色設(shè)置,這里是用RGB顏色
run.font.size = Pt(15) # 字體大小設(shè)置,和word里面的字號相對應(yīng)
p.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER #設(shè)置對齊方式
#設(shè)置整個表格字體屬性
table.style.font.size=Pt(18)
table.style.font.color.rgb=RGBColor(255, 0, 0)
table.style.paragraph_format.alignment=WD_PARAGRAPH_ALIGNMENT.CENTER合并單元格
合并后單元格
添加行列#添加行
table.add_row()
'''
添加列
width:列寬
'''
table.add_column(width=Cm(1)) |
|
|