【问题标题】:python pptx determine a table width and heightpython pptx 确定表格的宽度和高度
【发布时间】:2016-11-16 19:21:59
【问题描述】:

我使用 python 2.7 和 python pptx。

我有一个数据表,需要它来确定宽度和高度,

我知道我可以像enter link description here这样改变文字大小

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

我发现我可以把桌子变成一张图片,然后轻松地改变它的大小,但这感觉不是正确的做法。

想法?

【问题讨论】:

  • pptx documentation 给出了一个示例,说明如何创建具有给定整体widthheight 的表。
  • 太好了,谢谢。请发表一个我可以接受的答案

标签: python python-2.7 python-pptx


【解决方案1】:

取自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

【讨论】:

    猜你喜欢
    • 2012-08-08
    • 2020-01-31
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多