PPT is not easy to use, but it is still needed. Here, 250 PPT is automatically generated by python-PPtx (0.6.7) using douban Top250 movie information, hoping to give office workers who organize PPT reports all the year around a new idea to emancipate productivity through examples
Final effect display
Where does the data come from?
The reptile caught it!
What if you don’t understand reptiles?
Top250 movie posters
Automatic production PPT one two three
Make PPT template first
The process of making stencil is the process of inserting a placeholder, can according to their own requirements into various placeholder, for example, watercress film Top250 demand is, insert images and text content, then choose from a placeholder, content, images, the template is good, and then adjust the contents of the template style and image position. You have a template that fits your requirements
Data preparation:
I directly wrote the original,python climb douban movie script, run it, the picture and text data are all the same “Attack the Worm” climb Douban movie poster (Top250)
Python programming (fill in the blanks according to the template and export the data to the final PPT)
The source code is as follows (fully annotated):
from pptx import Presentation
from pptx.util import Inches
# Get douban movie information
def getInfo():
movies_info = []
with open('./douban_movie_top250.txt') as f:
for line in f.readlines():
line_list = line.split("\ '")
one_movie_info = {}
one_movie_info['index'] = line_list[1]
one_movie_info['title'] = line_list[3]
one_movie_info['score'] = line_list[5]
try:
one_movie_info['desc'] = line_list[7]
except:
one_movie_info['desc'] = ' '
one_movie_info['image_path'] = "./Top250_movie_images/"+ str(line_list[1]) + '_' + line_list[3] + ".jpg"
movies_info.append(one_movie_info)
return movies_info
# to create PPT
def createPpt(movies_info):
prs = Presentation('model.pptx')
for movie_info in movies_info:
Get the number of templates
templateStyleNum = len(prs.slide_layouts)
Create a slide from the first template
oneSlide = prs.slides.add_slide(prs.slide_layouts[0])
Get all the positions that the template can fill
body_shapes = oneSlide.shapes.placeholders
for index, body_shape in enumerate(body_shapes):
if index == 0:
body_shape.text = movie_info['index']+movie_info['title']
elif index == 1:
img_path = movie_info['image_path']
body_shape.insert_picture(img_path)
elif index == 2:
body_shape.text = movie_info['desc']
elif index == 3:
body_shape.text = movie_info['score']
# Modification of PPT
prs.save('PPTX')
def main():
# Get douban movie information
movies_info = getInfo()
createPpt(movies_info)
if __name__ == '__main__':
main()
Copy the code
Python generates charts (douban movie Top20 score as an example)
# encoding: utf-8
from pptx import Presentation
from pptx.chart.data import ChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
# create slide
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
Define chart data
chart_data = ChartData()
chart_data.categories = ['Shawshank Redemption'.Farewell my Concubine.'This killer is not too cold'.Forrest Gump.'Life is Beautiful'.Spirited Away.'Titanic'.'Schindler's List'.Inception.wall-E.'The Pianist of the Sea'.'Three Idiots in Bollywood'.'Hachiko's Story'.'Spring in the Cattle class'.'The Wedding of the Great Saint'.'The Truman Show'.'the godfather'."My neighbor totoro"."Melting pot".Gone with the Wind]
chart_data.add_series(Douban Movie, (9.6.9.5.9.4.9.4.9.5.9.2.9.2.9.4.9.3.9.3.9.2.9.2.9.2.9.2.9.2.9.1.9.2.9.1.9.2.9.2))
# Add chart to slide
x, y, cx, cy = Inches(0), Inches(0), Inches(10), Inches(8)
slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
prs.save('Douban Top20 score chart. PPTX')
Copy the code
About data graphics: Python has many excellent graphics library, such as MatplotLab, and Google’s online programming tool Colabratory, can easily achieve data visualization, master the use of Python graphics library, basically can say good and PPT charts.
Tutorial involves I through baidu network backup resource sharing for everyone, in order to facilitate everyone to download, resource integration to a separate post, link is as follows: www.jianshu.com/p/4f28e1ae0…