gpt4 book ai didi

python pptx 判断一个表格的宽高

转载 作者:行者123 更新时间:2023-12-02 20:55:11 24 4
gpt4 key购买 nike

我使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com