|
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') |