- Free Python 3 Tutorial
- Control Flow
- Exception Handling
- Python Programs
- Python Projects
- Python Interview Questions
- Python Database
- Data Science With Python
- Machine Learning with Python
- Solve Coding Problems
- Convert Docx to Pdf using docx2pdf Module in Python
- Python | Generate QR Code using pyqrcode module
- Plotting Data on Google Map using Python's pygmaps package
- Pathlib module in Python
- Send Message on Instagram Using Instabot module in Python
- Introduction to Social Networks using NetworkX in Python
- Working with wav files in Python using Pydub
- Hiding and encrypting passwords in Python?
- Create temporary files and directories using tempfile
- Memory profiling in Python using memory_profiler
- How to perform multiplication using CherryPy in Python?
- Port scanner using 'python-nmap'
- Macronutrient analysis using Fitness-Tools module in Python
- Visual TimeTable using pdfschedule in Python
- Generate Captcha Using Python
- Python Script to create random jokes using pyjokes
- Download Instagram Reel using Python
- Conversion between binary, hexadecimal and decimal numbers using Coden module
- Python | Launch a Web Browser using webbrowser module
Creating and updating PowerPoint Presentations in Python using python – pptx
python-pptx is library used to create/edit a PowerPoint (.pptx) files. This won’t work on MS office 2003 and previous versions. We can add shapes, paragraphs, texts and slides and much more thing using this library.
Installation: Open the command prompt on your system and write given below command:
Let’s see some of its usage:
Example 1: Creating new PowerPoint file with title and subtitle slide.
Example 2: Adding Text-Box in PowerPoint.
Example 3: PowerPoint (.pptx) file to Text (.txt) file conversion.
Example 4: Inserting image into the PowerPoint file.
Example 5: Adding Charts to the PowerPoint file.
Example 6: Adding tables to the PowerPoint file.
Please Login to comment...
- python-modules
- python-utility
Improve your Coding Skills with Practice
What kind of Experience do you want to share?
- Mailing List
Practical Business Python
Taking care of business, one python script at a time
Creating Powerpoint Presentations with Python
Posted by Chris Moffitt in articles
Introduction
Love it or loathe it, PowerPoint is widely used in most business settings. This article will not debate the merits of PowerPoint but will show you how to use python to remove some of the drudgery of PowerPoint by automating the creation of PowerPoint slides using python.
Fortunately for us, there is an excellent python library for creating and updating PowerPoint files: python-pptx . The API is very well documented so it is pretty easy to use. The only tricky part is understanding the PowerPoint document structure including the various master layouts and elements. Once you understand the basics, it is relatively simple to automate the creation of your own PowerPoint slides. This article will walk through an example of reading in and analyzing some Excel data with pandas, creating tables and building a graph that can be embedded in a PowerPoint file.
PowerPoint File Basics
Python-pptx can create blank PowerPoint files but most people are going to prefer working with a predefined template that you can customize with your own content. Python-pptx’s API supports this process quite simply as long as you know a few things about your template.
Before diving into some code samples, there are two key components you need to understand: Slide Layouts and Placeholders . In the images below you can see an example of two different layouts as well as the template’s placeholders where you can populate your content.
In the image below, you can see that we are using Layout 0 and there is one placeholder on the slide at index 1.
In this image, we use Layout 1 for a completely different look.
In order to make your life easier with your own templates, I created a simple standalone script that takes a template and marks it up with the various elements.
I won’t explain all the code line by line but you can see analyze_ppt.py on github. Here is the function that does the bulk of the work:
The basic flow of this function is to loop through and create an example of every layout included in the source PowerPoint file. Then on each slide, it will populate the title (if it exists). Finally, it will iterate through all of the placeholders included in the template and show the index of the placeholder as well as the type.
If you want to try it yourself:
Refer to the input and output files to see what you get.
Creating your own PowerPoint
For the dataset and analysis, I will be replicating the analysis in Generating Excel Reports from a Pandas Pivot Table . The article explains the pandas data manipulation in more detail so it will be helpful to make sure you are comfortable with it before going too much deeper into the code.
Let’s get things started with the inputs and basic shell of the program:
After we create our command line args, we read the source Excel file into a pandas DataFrame. Next, we use that DataFrame as an input to create the Pivot_table summary of the data:
Consult the Generating Excel Reports from a Pandas Pivot Table if this does not make sense to you.
The next piece of the analysis is creating a simple bar chart of sales performance by account:
Here is a scaled down version of the image:
We have a chart and a pivot table completed. Now we are going to embed that information into a new PowerPoint file based on a given PowerPoint template file.
Before I go any farther, there are a couple of things to note. You need to know what layout you would like to use as well as where you want to populate your content. In looking at the output of analyze_ppt.py we know that the title slide is layout 0 and that it has a title attribute and a subtitle at placeholder 1.
Here is the start of the function that we use to create our output PowerPoint:
This code creates a new presentation based on our input file, adds a single slide and populates the title and subtitle on the slide. It looks like this:
Pretty cool huh?
The next step is to embed our picture into a slide.
From our previous analysis, we know that the graph slide we want to use is layout index 8, so we create a new slide, add a title then add a picture into placeholder 1. The final step adds a subtitle at placeholder 2.
Here is our masterpiece:
For the final portion of the presentation, we will create a table for each manager with their sales performance.
Here is an image of what we’re going to achieve:
Creating tables in PowerPoint is a good news / bad news story. The good news is that there is an API to create one. The bad news is that you can’t easily convert a pandas DataFrame to a table using the built in API . However, we are very fortunate that someone has already done all the hard work for us and created PandasToPowerPoint .
This excellent piece of code takes a DataFrame and converts it to a PowerPoint compatible table. I have taken the liberty of including a portion of it in my script. The original has more functionality that I am not using so I encourage you to check out the repo and use it in your own code.
The code takes each manager out of the pivot table and builds a simple DataFrame that contains the summary data. Then uses the df_to_table to convert the DataFrame into a PowerPoint compatible table.
If you want to run this on your own, the full code would look something like this:
All of the relevant files are available in the github repository .
One of the things I really enjoy about using python to solve real world business problems is that I am frequently pleasantly surprised at the rich ecosystem of very well thought out python tools already available to help with my problems. In this specific case, PowerPoint is rarely a joy to use but it is a necessity in many environments.
After reading this article, you should know that there is some hope for you next time you are asked to create a bunch of reports in PowerPoint. Keep this article in mind and see if you can find a way to automate away some of the tedium!
- ← Best Practices for Managing Your Code Library
- Adding a Simple GUI to Your Pandas Script →
Subscribe to the mailing list
Submit a topic.
- Suggest a topic for a post
- Pandas Pivot Table Explained
- Common Excel Tasks Demonstrated in Pandas
- Overview of Python Visualization Tools
- Guide to Encoding Categorical Values in Python
- Overview of Pandas Data Types
Article Roadmap
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.
Spire.Presentation-for-Python 8.8.0
pip install Spire.Presentation-for-Python Copy PIP instructions
Released: Aug 7, 2023
A 100% standalone Power Point Python API for Processing Power Point Files
Project links
View statistics for this project via Libraries.io , or by using our public dataset on Google BigQuery
License: Free To Use But Restricted, Other/Proprietary License
Author: E-iceblue
Requires: Python >=3.9
Maintainers
Classifiers
- Free To Use But Restricted
- Other/Proprietary License
- Microsoft :: Windows
- POSIX :: Linux
- Python :: 3.6
Project description
Standalone powerpoint compatible python api for efficient presentation handling.
Product Page | Documentation | Examples | Forum | Temporary License | Customized Demo
Spire.Presentation for Python is a comprehensive PowerPoint compatible API designed for developers to efficiently create, modify, read, and convert PowerPoint files within Python programs. It offers a broad spectrum of functions to manipulate PowerPoint documents without any external dependencies.
Spire.Presentation for Python supports a wide range of PowerPoint features, such as adding and formatting text, tables, charts, images, shapes, and other objects, inserting and modifying animations, transitions, and slide layouts, generating and managing master slides, and many more.
This professional Python API also enables developers to easily convert PowerPoint files to various formats with high quality, including PDF, SVG, image, HTML, XPS, and more.
Support for Various PowerPoint Versions
- PPT - PowerPoint Presentation 97-2003
- PPS - PowerPoint SlideShow 97-2003
- PPTX - PowerPoint Presentation 2007/2010/2013/2016/2019
- PPSX - PowerPoint SlideShow 2007, 2010
High-Quality and Efficient PowerPoint File Conversion
Spire.Presentation for Python allows conversion from PowerPoint files to images, PDF, HTML, XPS, and SVG and interconversion between PowerPoint Presentation formats.
Support for Rich Presentation Manipulation Features
- Work with PowerPoint Charts
- Print PowerPoint Presentations
- Work with SmartArtImages and Shapes
- Audio and Video
- Protect Presentation Slides
- Text and Image Watermark
- Merge Split PowerPoint Document
- Comments and Notes
- Manage PowerPoint Tables
- Set Animations on Shapes
- Manage Hyperlink
- Extract Text and Image
- Replace Text
Create a PowerPoint document in Python
Convert powerpoint files to pdf, convert powerpoint files to images, set passwords for powerpoint presentations, project details, release history release notifications | rss feed.
Aug 7, 2023
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages .
Source Distributions
Built distribution.
Uploaded Aug 7, 2023 py3
Hashes for Spire.Presentation_for_Python-8.8.0-py3-none-win_amd64.whl
- português (Brasil)
Supported by
Automate PowerPoint Slides Creation with Python
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 .
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.
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
You are part of the distribution planning team of an international clothing retailer with stores on all continents.
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,
- Extract data from the Warehouse Management System (WMS)
- Process data and built visuals with Python
- Prepare a PowerPoint presentation
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
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
You can find the source code with dummy data here: Github
Let us explore all the steps to generate your final report with python.
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
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.
Create the visuals
Create a simple bar plot chart that shows the number of Lines and Orders prepared per day.
Save the charts
In order to be added to the PowerPoint, you need to save it locally.
Add comments and insights
You can add comments based on the chart you share that will summarize the performance of each week.
Include these comments under the visuals for more clarity.
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.
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
💡 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.
💡 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.
Conclusion & Next Steps
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
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,
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.
Automate Video Editing with Python
Automate graphic design using python, automate flash cards creation for language learning with python.
- Trending Categories
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
How to create powerpoint files using Python
Introduction.
We’ve all had to make PowerPoint presentations at some point in our lives. Most often we’ve used Microsoft’s PowerPoint or Google Slides.
But what if you don’t have membership or access to the internet? Or what if you just wanted to do it the “programmers” way?
Well, worry not for Python’s got your back!
In this article you’ll learn how to create a PowerPoint file and add some content to it with the help of Python. So let’s get started!
Getting Started
Throughout this walkthrough, we’ll be using the python-pptx package. This package supports different python versions ranging from 2.6 to 3.6.
So, make sure you have the right version of Python installed on your computer first.
Next, open your terminal and type −
Once the module is successfully installed, you are all set to start coding!
Importing the Modules
Before we get into the main aspects of it, we must first import the right modules to utilise the various features of the package.
So, let’s import the presentation class that contains all the required methods to create a PowerPoint.
Now, we are all set to create a presentation.
Creating a Presentation
Let us now create an object of the Presentation class to access its various methods.
Next, we need to select a layout for the presentation.
As you can see, there are nine different layouts. In the pptx module, each layout is numbered from 0 to 8. So, “Title Slide” is 0 and the “Picture with Caption” is 8.
So, let us first add a title slide.
Now, we have created a layout and added a slide to our presentation.
Let us now add some content to the first slide.
In the above lines, we first add a title to the “first slide” and a subtitle using the placeholder.
Now, let us save the presentation. We can do this using the save command.
If you run the program, it will save the PowerPoint presentation in the directory where your program is saved.
You have successfully created your PowerPoint presentation.
Creating a second slide and adding some content
Firstly, you’ll need to import additional methods to add content.
Let us first create and add the second slide.
Adding title for the next slide,
Now, we must create a textbox and move its layout to suit our needs.
Let us position it and adjust its margins in inches.
The above line of code will place a textbox 3 Inches from left and 1.5 Inches from the top with a width of 3 Inches and height of 1 Inch.
Once we have the layout and position fixed, time to create a textframe to add content to.
Now to add a paragraph of content,
Finally, save the presentation again using the save method.
That’s it! You can now create your own presentation with the help of Python.
And there are a lot more features within the pptx package that allows you to completely customise your presentation from A-Z just the way you do it in GUI.
You can add images, build charts, display statistics and a lot more.
You can go through python-pptx official documentation for more syntaxes and features.
Related Articles
- How to convert PDF files to Excel files using Python?
- How to remove swap files using Python?
- How to Create a list of files, folders, and subfolders in Excel using Python?
- How to rename multiple files recursively using Python?
- How to add audio files using Python kivy
- How to close all the opened files using Python?
- How to touch all the files recursively using Python?
- How to ignore hidden files using os.listdir() in Python?
- How to remove hidden files and folders using Python?
- How to read text files using LINECACHE in Python
- Tips for Using PowerPoint Presentation More Efficiently
- PowerPoint Alternatives
- How to copy files to a new directory using Python?
- How are files added to a tar file using Python?
- How are files added to a zip file using Python?
Kickstart Your Career
Get certified by completing the course
Python Tutorial
Python oops, python mysql, python mongodb, python sqlite, python questions, python tkinter (gui), python web blocker, related tutorials, python programs.
- Send your Feedback to [email protected]
Help Others, Please Share
Learn Latest Tutorials
Transact-SQL
Reinforcement Learning
R Programming
React Native
Python Design Patterns
Python Pillow
Python Turtle
Preparation
Verbal Ability
Interview Questions
Company Questions
Trending Technologies
Artificial Intelligence
Cloud Computing
Data Science
Machine Learning
B.Tech / MCA
Data Structures
Operating System
Computer Network
Compiler Design
Computer Organization
Discrete Mathematics
Ethical Hacking
Computer Graphics
Software Engineering
Web Technology
Cyber Security
C Programming
Control System
Data Mining
Data Warehouse
IMAGES
VIDEO
COMMENTS
6 min read · Sep 26, 2022 (Image by Author) Do you find yourself spending more time creating PowerPoint presentations than actually analyzing data? With Python, you can automate the creation of these presentations and focus on what really matters — improving your logistics operations.
python-pptx is library used to create/edit a PowerPoint (.pptx) files. This won't work on MS office 2003 and previous versions. We can add shapes, paragraphs, texts and slides and much more thing using this library. Installation: Open the command prompt on your system and write given below command: pip install python-pptx
Fortunately for us, there is an excellent python library for creating and updating PowerPoint files: python-pptx. The API is very well documented so it is pretty easy to use. The only tricky part is understanding the PowerPoint document structure including the various master layouts and elements.
python-pptx is a Python library for creating, reading, and updating PowerPoint (.pptx) files. A typical use would be generating a PowerPoint presentation from dynamic content such as a database query, analytics output, or a JSON payload, perhaps in response to an HTTP request and downloading the generated PPTX file in response.
1- Getting Started 2- Adding Images 3- Adding Charts 4- Implementation Now I'll show you the basics of creating PowerPoint slides with Python. Getting Started python-pptx is a Python library for creating and updating PowerPoint files. This article is going to be a basic introduction to this package.
Steve Canny's python-pptx is a great library for getting started using Python to create dynamic PowerPoint slides. PowerPoint presentations are often short, sweet, and full of pictures...
388 38K views 3 years ago Create Powerpoint Presentations with Python! In this tutorial I will be showing you how to create POWERPOINT PRESENTATIONS using only Python. This tutorial...
To create a PowerPoint file from a template or existing presentation just add the file path to this step Presentaion ("Path/to/file.pptx"). After creating the prs object I assigned several of the more common slide layouts to variables.
python-pptx is a Python library for creating, reading, and updating PowerPoint (.pptx) files. A typical use would be generating a PowerPoint presentation from dynamic content such as a database query, analytics output, or a JSON payload, perhaps in response to an HTTP request and downloading the generated PPTX file in response.
python-pptx allows you to create new presentations as well as make changes to existing ones. Actually, it only lets you make changes to existing presentations; it's just that if you start with a presentation that doesn't have any slides, it feels at first like you're creating one from scratch.
Spire.Presentation for Python is a comprehensive PowerPoint compatible API designed for developers to efficiently create, modify, read, and convert PowerPoint files within Python programs. It offers a broad spectrum of functions to manipulate PowerPoint documents without any external dependencies.
To create a new presentation, you'll need to create a PowerPoint object. You can do this using the following code: from pptx import Presentation presentation = Presentation () This code creates a new PowerPoint presentation object and assigns it to the presentation variable. Adding Slides
Creating a PowerPoint document using Python allows you to automate the process of generating professional presentations with ease. By leveraging libraries such as Spire.Presentation, you can ...
1 ....if you know how to LaTeX, it might be easier to just use beamer. - NightShadeQueen Jul 5, 2015 at 18:32 Add a comment 2 Answers Sorted by: 17 Check out the python-pptx library. Its useful for creating and updating PowerPoint .pptx files. Also for some quick examples in python-pptx with screenshots, you can check this link. Share
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. Daily Analysis Slide by WEEK
Next, open your terminal and type − pip install python-pptx Once the module is successfully installed, you are all set to start coding! Importing the Modules Before we get into the main aspects of it, we must first import the right modules to utilise the various features of the package.
Create professional looking PowerPoint presentations using python programming language and python-pptxSee: https://python-pptx.readthedocs.org/en/latest/user...
In this tutorial I will be showing you how to create amazing POWERPOINT PRESENTATIONS using only Python. This tutorial provides a step-by-step walk-through m...
Using python-pptx. To help us automate the PowerPoint presentation report, we would use the Python package called python-pptx. It is a Python package developed to create and update PowerPoint files. To start using the package, we need to install it first with the following code. pip install python-pptx.
Creating a new PowerPoint file with the title and subtitle slide. We can create a new PowerPoint file using the Presentation class of the pptx library. We can then create a slide layout using the slide_layouts attribute and create a slide object to add to the presentation file using the add_slide () method. We can add the title and subtitles to ...
One solution for you would be to use the PowerPoint Viewer program instead. PPT Viewer is set to open a PowerPoint file straight away in Presentation mode. Alternatively, you can use the argument /s to start Powerpoint. "powerpoint.exe /s <filename>.ppt". This will be equivalent to telling PowerPoint to straight away open up in Presentation mode.