如何使用 pptx python 更改默认表格样式?

Jon*_*Lam 1 python powerpoint python-3.x python-pptx

我正在使用 pptx python 创建一个表

参考:https : //python-pptx.readthedocs.io/en/latest/dev/analysis/tbl-table.html

创建表格时,我获得了默认表格样式,我想更改它。有什么推荐吗?

x, y, cx, cy = Inches(4.5), Inches(1.5), Inches(4.0), Inches(0)
shape = slide.shapes.add_table(7, 5, x, y, cx, cy)
table = shape.table
Run Code Online (Sandbox Code Playgroud)

我在想,table.apply_style()但我无法弄清楚正确的语法

在此处输入图片说明

Jon*_*Lam 5

好的找到了解决方案

x, y, cx, cy = Inches(4.5), Inches(1.5), Inches(4.0), Inches(0)
shape = slide.shapes.add_table(7, 5, x, y, cx, cy)
table = shape.table

tbl =  shape._element.graphic.graphicData.tbl
style_id = '{1FECB4D8-DB02-4DC6-A0A2-4F2EBAE1DC90}'
tbl[0][-1].text = style_id
Run Code Online (Sandbox Code Playgroud)

我正在使用 Medium Style 1 Accent 3,替换为sytle_id在此列表中找到的 GUI:https : //github.com/scanny/python-pptx/issues/27#issuecomment-263076372

  • 非常感谢您的见解。我觉得这应该是 python pptx 关于表格样式的标准文档的一部分。 (2认同)

小智 5

我在https://github.com/mbachtell/python-pptx-table-styles生成了幻灯片,其中演示了每种表格样式。

如果其他人遇到这样的需要。