2016-11-16 53 views
0

我使用Python 2.7使用蟒PPTX。蟒PPTX確定表的寬度和高度

我有數據表,它需要雙腳一定的寬度和高度,

我瞭解到,我可以改變文字大小,像這樣enter link description here

但我想改變整個表的大小適合一個確切的位置,並改變字體大小,並操縱行高和寬度,它似乎都太複雜,難以處理,我發現我可以把錶轉換爲圖像,而不是輕易地改變它的大小但那並不覺得這是正確的。

想法?

+0

的[PPTX文檔】(https://python-pptx.readthedocs.io/en/latest/user/quickstart.html#add-table-example)給出瞭如何創建一個表的例子有整體給定'width'和'height'。 –

+0

太好了,謝謝。請發佈我可以接受的答案 – thebeancounter

回答

2

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