在Scanny的代码和pptx documentation的基础上,我们可以定义一个这样的函数来打印整个现有python pptx表对象的维度:from pptx import Presentation
from pptx.util import Inches, Cm, Pt
def table_dims(table, measure = 'Inches'):
"""
Returns a dimensions tuple (width, height) of your pptx table
object in Inches, Cm, or Pt.
Defaults to Inches.
This value can then be piped into an Inches, Cm, or Pt call to
generate a new table of the same initial size.
"""
widths = []
heights = []
for column in table.columns:
widths.append(column.width)
for row in table.rows:
heights.append(row.height)
# Because the initial widths/heights are stored in a strange format, we'll convert them
if measure == 'Inches':
total_width = (sum(widths)/Inches(1))
total_height =