6/21/2017

(Open Source) 使用Python 來製作 pptx

"Where are you going?" 在跑金面山時讓我想到Alice Wonderland,可惜的是並沒有出現那隻貓

“Cat: Where are you going?
Alice: Which way should I go?
Cat: That depends on where you are going.
Alice: I don’t know.
Cat: Then it doesn’t matter which way you go.”

Lewis Carroll, Alice in Wonderland
儘管這年頭碰到沒有Office或其他辦公室套件(ex. Google suite)很少, 但是有一個問題是我們無法透過檔案總管或是X軟出品的套件來找到PPT內容的關鍵字, 也無法自動化產出(有出週報與月報的切身之痛.....浪費人生在剪貼簿)

python-pptx 套件很有趣的就是他可以做出這種無腦的簡報, 所以當資料量大的時候就變得很有效
Feature Support:
  • Round-trip any Open XML presentation (.pptx file) including all its elements
  • Add slides
  • Populate text placeholders, for example to create a bullet slide
  • Add image to slide at arbitrary position and size
  • Add textbox to a slide; manipulate text font size and bold
  • Add table to a slide
  • Add auto shapes (e.g. polygons, flowchart shapes, etc.) to a slide
  • Add and manipulate column, bar, line, and pie charts
  • Access and change core document properties such as title and subject
安裝的方式可以透過:  pip install python-pptx來安裝 這個套件, API Documentation可以參考這邊來編輯需要的範本. 希望可以善用python-pptx來做出搞出一個屬於自己的範本(這樣就可以無腦出報告?) 

延伸閱讀:
1. 變更資料夾所需要的套件 Python os module 
2. python-pptx(template) Hello World!
3. python-docx 
from pptx import Presentation

prs = Presentation()
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! by Tony"

prs.save('test.pptx')

沒有留言:

張貼留言

謝謝您的留言, 我會在收到通知後盡快回覆您的.
Thanks for your comment. l may reply once I got notification.