LoginSignup
1
0

More than 3 years have passed since last update.

python-pptxでA4サイズ

Last updated at Posted at 2020-10-15

pythonでパワポ報告書を(自動)生成するための小技

python-pptxではインチで扱うのが便利。
なので、A4サイズ==11.69 inch x 8.27 inchを使う。

(python-pptxは長さにEnglish Metric Units (EMU)という単位を使っている。これをインチ変換するメソッドが、pptx.util.Inchesである。)

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()

prs.slide_height=Inches(11.69)
prs.slide_width=Inches(8.27)

prs.save("./hoge.pptx")

これで、一応作れる。

image.png

ここに、タイトルのスライドレイアウトと白紙のスライドレイアウトを貼り付けるなら、

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()

prs.slide_height=Inches(11.69)
prs.slide_width=Inches(8.27)

# タイトルスライド
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)

title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"

# 白紙のスライド
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)

prs.save("./hoge.pptx")

image.png

となる。

参考

python-pptx 0.6.18 documentation

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0