Reputation: 99
If I write and execute this code
from pptx import Presentation
prs = Presentation()
slide_layout = prs.slide_layouts[0]
prs.save("Final.pptx")
It creates a PPT with just one slide, which is an unedited standard title slide.
But in MS Powerpoint I can see many layouts of my company. And I want to use their layout. Please tell me how to do it.
Upvotes: 1
Views: 2366
Reputation: 393
To use a “template” for a presentation you simply create a presentation with all the styles, logo, and layouts you want, delete all the slides (or leave some in if it suits), and then load that as your starting place.
from pptx import Presentation
prs = Presentation('custom-lay.pptx')
Upvotes: 0
Reputation: 24164
You can use Powerpoint to save a file with the layout you want, and then open it:
from pptx import Presentation
prs = Presentation('company-layout.pptx')
See the documentation:
You can open any PowerPoint 2007 or later file this way (.ppt files from PowerPoint 2003 and earlier won’t work). While you might not be able to manipulate all the contents yet, whatever is already in there will load and save just fine. The feature set is still being built out, so you can’t add or change things like Notes Pages yet, but if the presentation has them python-pptx is polite enough to leave them alone and smart enough to save them without actually understanding what they are.
If you use the same filename to open and save the file, python-pptx will obediently overwrite the original file without a peep. You’ll want to make sure that’s what you intend.
Upvotes: 3