PowerPoint Intermediate Lesson 6: Generate Slides From Data With Python

PowerPoint Intermediate Lesson 6: Generate Slides From Data With Python 1

📎 This article includes 3 downloadable practice files ↓

⏱ 2 min read

📘 PowerPoint Intermediate Course · Lesson 6 of 8

Advertisement

A monthly deck with one slide per region is the same work every month. A short script does it in a second, and the charts are real PowerPoint charts you can still edit.

from openpyxl import load_workbook
from pptx import Presentation
from pptx.util import Inches
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE

wb = load_workbook("ppt-inter-sales-data.xlsx", data_only=True)
p = Presentation()                      # or Presentation("brand-template.pptx")
for reg, sales, target, pct in wb["Regions"].iter_rows(min_row=2, values_only=True):
    s = p.slides.add_slide(p.slide_layouts[5])          # Title Only
    s.shapes.title.text = f"{reg}: Rs {sales} lakh ({pct}% of target)"
    cd = CategoryChartData(); cd.categories = ["Sales", "Target"]; cd.add_series("Rs lakh", (sales, target))
    s.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(1), Inches(1.6), Inches(7), Inches(5), cd)
p.save("monthly-review.pptx")

Our generated deck has 6 slides: title, one per region with a sales vs target chart and an Achieved / Close / Behind label, and a 12-month trend. PowerPoint opened it without complaint.

💡 Start from your brand template (lesson 2): Presentation("brand.pptx") and use its layouts by index (p.slide_layouts[...]). Print [l.name for l in p.slide_layouts] to find them.

Install once: pip install python-pptx openpyxl. New to Python? See the Python Intermediate Course.

Practice

Download the practice deck: the first slide lists the tasks. Run the script next to the Excel file and open monthly-review.pptx.

📎 Practice files for this article

⬇ Download all 3 files (ZIP · 64 KB)

  • 📗
    Sales data (Excel)Regions (sales, target, % of target) and 12 months of sales, used in lessons 3, 6 and 8.
    ⬇ XLSX · 12 KB
  • 🐍
    Python scriptReads the Excel file and builds the deck.
    ⬇ PY · 1 KB
  • 📙
    Generated deckThe output, re-opened and checked in PowerPoint.
    ⬇ PPTX · 63 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *