作者twh2000 (twh2000)
看板Python
标题[问题]python-docx套件无法对储存格设定字型大小
时间Mon Dec 27 09:57:37 2021
python-docx套件在WORD新增表格後无法对特定储存格(无资料)设定字型大小
这里指的是新增表格後,储存格无资料的情况下
有资料是可以修改字型大小没问题
doc = Document()
table_= doc.add_table(4,4,'Table Grid')
table_.style.font.size=Pt(16)
以上可以设定,但是是对全部表格都设定,我想单独设定第1行的字型大小
table_.cell(0,0).paragraphs[0].font.size=Pt(16)
table_.cell(0,0).paragraphs[0].runs[0].font.size=Pt(16)
table_.cell(0,0).paragraphs[0].add_run('').font.size = Pt(16)
table_.rows[0].cells[0].paragraphs[0].font.size=Pt(16)
table_.rows[0].cells[0].paragraphs[0].runs[0].font.size=Pt(16)
table_.rows[0].cells[0].paragraphs[0].add_run('').font.size = Pt(16)
这6种方式都不行,还有什麽方式可以单独设定字型大小的
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.35.160.80 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1640570259.A.E45.html
1F:→ Pieteacher: 用 pywin32套件 12/27 12:47
3F:→ twh2000: 感谢两位大大的指导,可以设定了 3Q 12/27 17:28