I am using python-pptx library to combine two powerpoint files and everything I try constantly fails. Has anyone faced a similar issue?
I tried the following:
from pptx import Presentation
import os
prs1 = Presentation("Test1.pptx")
prs2 = Presentation("Test2.pptx")
for slide in prs2.slides:
sl = prs1.slides.add_slide(prs1.slide_layouts[1])
sl.shapes.title.text = slide.shapes.title.text
sl.placeholders[1].text = slide.placeholders[1].text
prs1.save("Test3.pptx")
This fails and I keep getting errors. I also tried this:
import os
import json
import os
import numpy as np
from pptx import Presentation
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
from pptx.util import Pt
import math
from pptx.util import Inches
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE
from pptx import Presentation
combined_presentation = Presentation()
FinancialSummaryPPT = Presentation('Test1.pptx')
for slide in FinancialSummaryPPT.slides:
new_slide = combined_presentation.slides.add_slide(slide.slide_layout)
for shape in slide.shapes:
if shape.has_text_frame:
text_frame = shape.text_frame
new_shape = new_slide.shapes.add_textbox(shape.left, shape.top, shape.width, shape.height)
new_text_frame = new_shape.text_frame
new_text_frame.word_wrap = text_frame.word_wrap
for paragraph in text_frame.paragraphs:
new_paragraph = new_text_frame.add_paragraph()
for run in paragraph.runs:
new_run = new_paragraph.add_run()
new_run.text = run.text
new_run.bold = run.bold
new_run.italic = run.italic
new_run.underline = run.underline
new_run.font.size = run.font.size
new_run.font.name = run.font.name
elif shape.has_table:
table = shape.table
new_table = new_slide.shapes.add_table(rows=table.rows.__len__(), cols=table.columns.__len__(),
left=shape.left, top=shape.top,
width=shape.width, height=shape.height)
for i in range(table.rows.__len__()):
for j in range(table.columns.__len__()):
new_table.cell(i, j).text = table.cell(i, j).text
combined_presentation.save('Combined.pptx')
I get an error. Is there a better way to do this?