LoginSignup
10
23

More than 5 years have passed since last update.

pythonで作ったパワーポイントで自己紹介してみた

Last updated at Posted at 2018-01-08

これまでの仕事で、手動でレポートを書くことが多かったのですが、最近pythonでパワーポイントを作成できることを知ったので、勉強がてら自己紹介PPTXを作成します。

pythonでパワーポイントを作成できると、毎週・毎月報告するようなKPIレポートなどを自動で作成することが可能です。今回はpython-pptxというライブラリを利用します。

pip install でvirtualenv内にライブラリを入れました。

pip install python-pptx

なお、自己紹介は未完成なので更新していきますのであしからず。

注意しているのは以下のような点です。

  1. ページレイアウトの替え方
  2. 箇条書きの作り方
  3. 太字の仕方
  4. フォントサイズの替え方

今後実装したいのは以下の点。お待ちください。

  • 画像挿入
  • 表挿入
  • 自動でKPIの数値を挿入
  • スライドマスタを変更する
from pptx import Presentation
from datetime import datetime
from pptx.util import Pt

today = datetime.today().strftime("%Y%m%d")

prs = Presentation()

# P1: title page
title_slide_layout = prs.slide_layouts[0]  # page layout
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]

title.text = "Introduce Myself"
subtitle.text = "@ishio"

# P2
bullet_slide_layout = prs.slide_layouts[1]  # page layout
slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes

title_shape = shapes.title
body_shape = shapes.placeholders[1]

title_shape.text = 'Introduce My Hobby'
title_shape.text_frame.paragraphs[0].font.size = Pt(32)  # font size
title_shape.text_frame.paragraphs[0].font.bold = True  # font bold

tf = body_shape.text_frame
tf.text = 'Reading books'
tf.paragraphs[0].font.size = Pt(28)  # font size
tf.paragraphs[0].font.bold = True  # font bold

p = tf.add_paragraph()
p.text = 'Read 57 books in 2017'
p.level = 1  # down the bullet level
p.font.size = Pt(24)  # font size

p = tf.add_paragraph()
p.text = 'Try to read 70 books in 2018'
p.level = 1  # down the bullet level
p.font.size = Pt(24)  # font size

# This is a space between bullets
p = tf.add_paragraph()
p.font.size = Pt(28)  # font size

p = tf.add_paragraph()
p.text = 'Watching and playing football'
tf.paragraphs[4].font.size = Pt(28)  # font size
tf.paragraphs[4].font.bold = True  # font bold

# This is a space between bullets
p = tf.add_paragraph()
p.text = 'Love Urawa Reds'
p.level = 1
p.font.size = Pt(24)  # font size

p = tf.add_paragraph()
p.text = 'Play futsal every weekend to keep myself healthy'
p.level = 1
p.font.size = Pt(24)  # font size

prs.save('test_%s.pptx' % today)

作成されたPPTは以下のような感じです。

P1
image.png

P2
image.png

2018年、よろしくお願いします。

@Ishio

10
23
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
10
23