Skip to content

Instantly share code, notes, and snippets.

@seandavi
Created August 16, 2024 19:35
Show Gist options
  • Save seandavi/9e6404cd414be8584f1299fdf8bc3926 to your computer and use it in GitHub Desktop.
Save seandavi/9e6404cd414be8584f1299fdf8bc3926 to your computer and use it in GitHub Desktop.
Powerpoint from python code

Powerpoint from code

Using code for a powerpoint is a useful approach to have chatgpt and other LLMs create powerpoint slides from documents or a textual description.

Usage

pip install -r requirements.txt
python make_powerpoint.py
from pptx import Presentation
from pptx.util import Inches
from pptx.enum.chart import XL_CHART_TYPE
# Create a presentation object
prs = Presentation()
# Add a title slide
slide_layout = prs.slide_layouts[0] # 0 is the layout for the title slide
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Welcome to the Presentation"
subtitle.text = "This presentation contains text, a table, and a chart."
# Add a slide with a title and content
slide_layout = prs.slide_layouts[1] # 1 is the layout for title and content
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
content = slide.placeholders[1]
title.text = "Agenda"
content.text = "1. Introduction\n2. Main Content\n3. Conclusion"
# Add a slide with a table
slide_layout = prs.slide_layouts[5] # 5 is the layout for title and content
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
title.text = "Data Table"
# Define table dimensions
rows = 3
cols = 4
left = Inches(2)
top = Inches(2)
width = Inches(6)
height = Inches(1.5)
# Add table
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Set column headings
table.columns[0].width = Inches(1.5)
table.columns[1].width = Inches(1.5)
table.columns[2].width = Inches(1.5)
table.columns[3].width = Inches(1.5)
table.cell(0, 0).text = 'Header 1'
table.cell(0, 1).text = 'Header 2'
table.cell(0, 2).text = 'Header 3'
table.cell(0, 3).text = 'Header 4'
# Add data to the table
table.cell(1, 0).text = 'Data 1'
table.cell(1, 1).text = 'Data 2'
table.cell(1, 2).text = 'Data 3'
table.cell(1, 3).text = 'Data 4'
table.cell(2, 0).text = 'Data 5'
table.cell(2, 1).text = 'Data 6'
table.cell(2, 2).text = 'Data 7'
table.cell(2, 3).text = 'Data 8'
prs.save('combined_presentation.pptx')
@andreinhafcg
Copy link

from pptx import Presentation

Criação da apresentação

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "O Papel das Organizações Não Governamentais na Promoção da Saúde"
slide.placeholders[1].text = "Nome do aluno\nDisciplina\nProfessor\nData"

Outros slides resumidos

slides_info = [
("Introdução", "ONG’s são entidades sem fins lucrativos com papel essencial na saúde.\nPromovem prevenção, apoio e sensibilização."),
("O Papel das ONG’s", "- Prevenção\n- Apoio direto\n- Complemento aos serviços públicos"),
("Exemplos de ONG’s", "HIV/SIDA: Abraço\nCancro: Liga Contra o Cancro\nSaúde Mental: Encontrar+se\nDoenças Raras: Raríssimas\nDependências: APDES"),
("Associação APFQ", "Fundada em 1997\nMissão: apoiar doentes com Fibrose Quística\nApoio psicológico e social\nCampanhas e testemunhos"),
("Conclusão", "ONG’s são fundamentais para a promoção da saúde e justiça social."),
("Bibliografia", "https://www.apfq.pt\nhttps://abraco.pt\nhttps://ligacontracancro.pt\nhttps://rarissimas.pt")
]

for title, content in slides_info:
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = title
content_frame = slide.placeholders[1].text_frame
for line in content.split('\n'):
p = content_frame.add_paragraph()
p.text = line

prs.save("Trabalho_ONG_Saude_APFQ.pptx")

@seandavi
Copy link
Author

seandavi commented May 3, 2025

Muito obrigado, @andreinhafcg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment