python pptx 判断一个表格的宽高

标签 python python-2.7 python-pptx

我使用 python 2.7 和 python pptx。

我有一个数据表,需要它以一定的宽度和高度为单位,

我了解到我可以像这样更改文本大小 enter link description here

但我希望更改整个表格的大小以适应确切的位置,并更改字体大小,并操纵行高和列宽,这一切似乎都太复杂且难以处理,

我发现我可以将表格变成图像,而不是轻松地更改它的大小,但感觉这不是正确的做法。

想法?

最佳答案

示例取自 pptx documentation给出了一个很好的示例,说明如何创建具有给定整体 widthheight 的表格,如下所示:

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
title_only_slide_layout = prs.slide_layouts[5]
slide = prs.slides.add_slide(title_only_slide_layout)
shapes = slide.shapes

shapes.title.text = 'Adding a Table'

rows = cols = 2
left = top = Inches(2.0)
width = Inches(6.0)
height = Inches(0.8)

table = shapes.add_table(rows, cols, left, top, width, height).table

# set column widths
table.columns[0].width = Inches(2.0)
table.columns[1].width = Inches(4.0)

# write column headings
table.cell(0, 0).text = 'Foo'
table.cell(0, 1).text = 'Bar'

# write body cells
table.cell(1, 0).text = 'Baz'
table.cell(1, 1).text = 'Qux'

prs.save('test.pptx')

util Module还提供了指定维度的替代方法,例如 CentipointsCmEmuMmPtPx

关于python pptx 判断一个表格的宽高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40626741/

相关文章:

python - Pandas GroupBy 日期范围取决于每一行

python - Python C 扩展的 DLL 文件的兼容性

python - 关于负正则表达式的另一个问题

Python Puzzle 代码审查(剧透)

firefox - 安装 Firefox Addon SDK Python 时出错

python - 为什么我在 python pptx 上出现一个形状的组形状错误?

python - Pandas:将分组的 df 转换为以两列作为键、值对的字典列表

python - 如何在 Python 中同时对多个不同的列表进行相同的迭代

python - 如何使用 pptx python 库更改 PPT 幻灯片上项目符号列表的缩进

Python PPTX - 如何设置图表轴数格式和范围