0% found this document useful (0 votes)
173 views17 pages

Automate PowerPoint Slides Creation With Python

This article discusses how to automate the creation of PowerPoint slides for supply chain operational reports using Python. It outlines a four-step process: extracting data from a warehouse management system, processing the data, generating visuals, and creating a PowerPoint presentation. The solution aims to enhance productivity by eliminating the need for manual slide preparation.

Uploaded by

jmanzungu2820
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views17 pages

Automate PowerPoint Slides Creation With Python

This article discusses how to automate the creation of PowerPoint slides for supply chain operational reports using Python. It outlines a four-step process: extracting data from a warehouse management system, processing the data, generating visuals, and creating a PowerPoint presentation. The solution aims to enhance productivity by eliminating the need for manual slide preparation.

Uploaded by

jmanzungu2820
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Automate PowerPoint Slides Creation with Python

Samir Saci Sep 27, 20225 min

Boost your Productivity with an Automated Tool for the Creation of Supply
Chain Operational PowerPoint Reports with Python.

Boost your Productivity with an Automated Tool for the Creation


of Supply Chain Operational PowerPoint Reports with Python

Article originally published on Medium.

Scenario

You are a distribution planning manager in the logistics


department of a fashion retail company.

To perform analysis, you connect to the warehouse


management system to extract and process data using an
automated tool built with Python.

However, you have to spend time manually putting these visuals


in slides for your weekly operational reviews.

Objective

In this article, we will build a solution to automatically create


PowerPoint slides with visuals and comments.
💌 New articles straight in your inbox for free: Newsletter

Have a look at the video version of this article,

Problem Statement
Scenario

You are part of the distribution planning team of


an international clothing retailer with stores on all continents.

Logistics Network — (Image by Author)

Your distribution network includes several local warehouses that


replenish the stores.

Monthly Operational Reviews

At the end of the month, you organize an operational review with


the store managers to assess the performance of the
distribution network.

To animate the discussion you prepare some slides,

1. Extract data from the Warehouse Management System


(WMS)
2. Process data and built visuals with Python
3. Prepare a PowerPoint presentation
Objective

To be efficient, you would like to automate the process of


PowerPoint deck creation.

Your solution will be fully automated

 Extract order lines of the last month from the WMS SQL
database
 Process the data and compute KPIs with key insights by
week
 Automatically put the visuals and insights in a PowerPoint
presentation

Process in 4 steps — (Image by Author)

Results

The final deck will have slides like the ones below:

 5 slides with visuals of the daily workload (left) and 1


slide for the monthly analysis of the order profile (right)
 A visual generated with Python
 A comment area will provide insights based on the visual
Final Results — (Image by Author)

Solutions
You can find the source code with dummy data here: Github

Let us explore all the steps to generate your final report with
python.

Steps to create your operational report on PowerPoint — (Image by Author)

Data Extraction

Connect to your WMS and extract shipment records

 Create your SQL Query to extract shipment records


 Use pandas.read_sql_query to do the query
 Results will be a pandas data frame

DATE WEEK DAY ORDERS LINES PCS SKU CITIES

2017-01-02 WEEK-1 MON 776 1367 1595.0 487 174

2017-01-03 WEEK-1 TUE 902 1550 1861.0 547 188

2017-01-04 WEEK-1 WED 1476 2252 2856.0 513 205

2017-01-05 WEEK-1 THU 909 1637 1972.0 519 175

2017-01-06 WEEK-1 FRI 1023 1720 1995.0 502 189


view rawinit.csv hosted with ❤ by GitHub

If you don’t have access to a WMS database, you can use the
dataset shared in the GitHub repo.
Process the data

Add a column that calculates the number of lines per order using
pandas.

DATE WEEK DAY ORDERS LINES PCS SKU CITIES LINES/ORDER


2017-01- 1595.
WEEK-1 MON 776 1367 487 174 1.7615979381443299
02 0

2017-01- 1861.
WEEK-1 TUE 902 1550 547 188 1.7184035476718404
03 0

2017-01- 2856.
WEEK-1 WED 1476 2252 513 205 1.5257452574525745
04 0

2017-01- 1972.
WEEK-1 THU 909 1637 519 175 1.800880088008801
05 0

2017-01- 1995.
WEEK-1 FRI 1023 1720 502 189 1.6813294232649072
06 0
view rawinit_process.csv hosted with ❤ by GitHub

Create the visuals

Create a simple bar plot chart that shows the number of Lines and
Orders prepared per day.

# Bar Plot: Orders/Lines


fig, ax = plt.subplots(figsize=(14, 7))
df_plot.plot.bar(figsize=(8, 6), edgecolor='black', x='DAY', y=['ORDERS',
'LINES'],
color=['tab:blue', 'tab:red'],
legend= True, ax = ax)
plt.xlabel('DAY', fontsize = 12)
plt.title('Workload per day (Lines/day)', fontsize = 12)
plt.show()
view rawbuild_chart.py hosted with ❤ by GitHub
Bar
plot— (Image by Author)
# Bar Plot: split per lines per orders
fig, ax = plt.subplots(figsize=(12, 6))
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[0], color='tab:blue', legend= True, ax = ax)
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[1], color='tab:red', legend= True, ax = ax)
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[2], color='tab:orange', legend= True, ax = ax)
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[3], color='darkblue', legend= True, ax = ax)
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[4], color='brown', legend= True, ax = ax)
df_lior.plot.bar(figsize=(10, 6), edgecolor='black', x='WEEK',
y=COLS_IN[5], color='grey', legend= True, ax = ax)
plt.xlabel('Week', fontsize = 14)
plt.ylabel('Number of Orders', fontsize = 14)
plt.title('Split of orders by number of lines/order', fontsize = 14)
plt.show()
view rawstacked.py hosted with ❤ by GitHub
Stacked Bar Plot — (Image by Author)

Save the charts

In order to be added to the PowerPoint, you need to save it


locally.

# save plot
filename = 'visual' + ".png"
path_plot = filename
fig.savefig(path_plot,
dpi=fig.dpi)
view rawsave_img.py hosted with ❤ by GitHub

Add comments and insights

You can add comments based on the chart you share that will
summarize the performance of each week.

# Add the insights


html_string = html_string.replace("WEEK", WEEK)
html_string = html_string.replace("total_lines",
total_lines)
html_string = html_string.replace("busy_day", busy_day)
html_string = html_string.replace("max_lines",
max_lines)
html_string = html_string.replace("avg_ratio",
avg_ratio)
html_string = html_string.replace("max_ratio",
max_ratio)
view rawadd_insights.py hosted with ❤ by GitHub

Include these comments under the visuals for more clarity.

Example of comments — (Image by Author)

Create the PowerPoint Decks


We will use the open-source library python-pptx to build our
PowerPoint decks.

For more details, have a look at the documentation.

Introduction Slide

We will start with a special introduction slide at the beginning of


the presentation.
First Slide —
(Image by Author)

Code

# Create the presentation object


prs = Presentation()

# Layout Choice for the introduction slide


image_slide_layout = prs.slide_layouts[5]
page = 1

'''Slide Introduction'''
# Create the slide
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
background = slide.background
fill = background.fill
fill.solid()
fill.fore_color.rgb = RGBColor(0, 32, 96)
# Add Title
title.text = "WAREHOUSE WORKLOAD ANALYSIS"
title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255,
255)
# Add Subtitle
subtitle.text = 'Orders/day for the last {}
weeks'.format(len(LIST_WEEKS))
subtitle.text_frame.paragraphs[0].font.color.rgb = RGBColor(255,
255, 255)
view rawintroduction.py hosted with ❤ by GitHub

Daily Analysis Slide by WEEK

The structure of your slide will be always the same

 A title on top (e.g: Warehouse Workload (WEEK-5))


 A picture at the centre of the slide
 A text box for the comment area

Slide Structure —
(Image by Author)

Code

'''Slides Analysis per Week'''


for WEEK in LIST_WEEKS:

# Create Plot
avg_ratio, max_ratio, busy_day, max_lines, total_lines =
analysis_week(df_day, WEEK)
# Create a slide
slide = prs.slides.add_slide(image_slide_layout)
shapes = slide.shapes
# Create Title
title_shape = shapes.title
title_shape.text = 'Warehouse Workload ({})'.format(WEEK)
# Add Image
left = Inches(0.75)
top = Inches(1.25)
pic = slide.shapes.add_picture('{}.png'.format(WEEK), left, top,
height=Inches(4.5))

# Build the Text Box


left = Inches(0.75)
top = Inches(1.5) + Inches(4)
width = Inches(9)
height = Inches(2)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
# Title
p = tf.add_paragraph()
p.text = 'Analysis'
p.font.size = Pt(18)
# First bullet point
p = tf.add_paragraph()
p.text = '• {} have been prepared during the week'.format(total_lines)
p.level = 1
# Second bullet point
p = tf.add_paragraph()
p.text = '• {} has been the busiest day with {}
prepared'.format(busy_day, max_lines)
p.level = 1
# Third bullet point
p = tf.add_paragraph()
p.text = '• {} on average with a maximum of {}'.format(avg_ratio,
max_ratio)
p.level = 1

# Add Pages
txBox = slide.shapes.add_textbox(Inches(9), Inches(6.75), Inches(1),
Inches(1))
tf = txBox.text_frame
p = tf.add_paragraph()
p.text = str('{}/{}'.format(page, len(LIST_WEEKS) + 1 ))
p.font.size = Pt(15)
page += 1
view rawdaily_orders.py hosted with ❤ by GitHub

💡 TIPS
You can change the position of the objects by modifying the
parameters of Inches() functions.

Weekly Analysis of Order Profile

In this slide, you will use a stacked bar plot chart and the
comments will be based on the full month scope.

Order Profile —
(Image by Author)

Code

# Add Analysis lines


total_orders, LIST_ANALYSIS = plot_split(df_lior)
# Create a slide
slide = prs.slides.add_slide(image_slide_layout)
shapes = slide.shapes
# Create Title
title_shape = shapes.title
title_shape.text = 'Order Profile'
# Add Image
left = Inches(0.75)
top = Inches(1.25)
pic = slide.shapes.add_picture('{}.png'.format('SPLIT'), left, top,
height=Inches(4.5))
# Build the Text Box
left = Inches(0.75)
top = Inches(1.5) + Inches(4)
width = Inches(9)
height = Inches(2)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
p = tf.add_paragraph()
p.text = '{} prepared'.format(total_orders)
p.font.size = Pt(18)
for l in LIST_ANALYSIS:
# First bullet point
p = tf.add_paragraph()
p.text = '• {}'.format(l)
p.level = 1
# Add Pages
txBox = slide.shapes.add_textbox(Inches(9), Inches(6.75), Inches(1),
Inches(1))
tf = txBox.text_frame
p = tf.add_paragraph()
p.text = str('{}/{}'.format(page, len(LIST_WEEKS) +1))
p.font.size = Pt(15)
page += 1

# Save
prs.save('Warehouse Workload Report.pptx')
view rawfinal_slide.py hosted with ❤ by GitHub

💡 TIPS
You can change the font size by modifying the parameter of the
functions Pt().

Finally, you have a PowerPoint file with 7 slides ready to be used


for your meetings.
PowerPoint Final — (Image by Author)

Conclusion & Next Steps


Conclusion

With this very simple example, you have a template to build your
own PowerPoint automation solution.

You can now,

 Add visuals, tables or smart visuals of PowerPoint (check the


documentation)
 Bring more insights or enrich the text with conditions

Next Steps
This python script can be launched locally on your computer with
one click.

You can also automate the report distribution by email using the
SMTP library of python.

For more details, you can have a look at this article I published a
few weeks ago,

Automate Operational Reports Distribution in HTML Emails using


Python
Automate the distribution of supply chain operational reports with visuals in HTML
emails using python.

Samir SaciSamir Saci


About Me

Let’s connect on Linkedin and Twitter, I am a Supply Chain


Engineer that is using data analytics to improve logistics
operations and reduce costs.

If you’re looking for tailored consulting solutions to optimize your


supply chain and meet sustainability goals, please contact me.

You might also like