How to place image files in either side of "Two Column" PowerPoint template using Report Generator?

Good morning,
I'm trying to use Report Generator with the PowerPoint API to code a repetative task of populating specific PNG image files in a PowerPoint presentation on multiple pages by placing image files in each side of "Two Column" PowerPoint template using Report Generator. I searched the documentation for how to create the placeholder for the left and right hand column of the slide, but couldn't find one. Below is the code I tried but the placeholder on line 5 is empty. Searching for "Two Content" also fails.
There may be other issues with this code on following lines. Please help if you can on this basic step. I will also appreciate help in sizing the left and right hand images to the slide edge on each side (6.5 x 6.5 in).
Thank you,
Phil
import mlreportgen.ppt.*
ppt = Presentation("WindPlots_TwoContent.pptx");
open(ppt);
slide1 = add(ppt, "Two Content");
content_placeholders = find(slide1, "Content");
img1 = "Wind_JulDec_2009.png";
left_content_ph = content_placeholders(1);
replace(left_content_ph, "Two Content", Picture("img1"));

 채택된 답변

Dear @Philip,
You can place images on both sides of a two‑column PowerPoint slide by creating your own custom template with placeholders designed for two images. Follow the following steps for the same:
  1. Create a new blank PowerPoint file.
  2. Go to View → Slide Master to open the master slide editor.
  3. Select the ‘Two Content’ layout from the panel on the right where all the layouts are displayed.
  4. Open the Selection Pane (Home → Editing → Select → Selection Pane).
  5. Click each placeholder in the Selection Pane to see which object it corresponds to on the slide. You can even rename the placeholders in the Selection Pane.
  6. Close the Slide Master view.
  7. Save this presentation (for example, “myTemplate.pptx”).
  8. Use this custom template when generating your PowerPoint file in MATLAB.
import mlreportgen.ppt.*
% Create a presentation that outputs to "WindPlots_TwoContent.pptx"
% and uses "myTemplate.pptx" as the template.
% (The template must contain a slide layout named "Two Content".)
ppt = Presentation("WindPlots_TwoContent.pptx", "myTemplate.pptx");
open(ppt);
% Add a new slide based on the "Two Content" layout from the template.
% If the template does not have this layout, this call will error.
slide1 = add(ppt, "Two Content");
imgLeftPath = "img1.jpg";
imgRightPath = "img2.jpg";
% Create Picture objects for each image.
picLeft = Picture(imgLeftPath);
picRight = Picture(imgRightPath);
% In your template, the two content placeholders are named
% "Content Placeholder 2" (left) and "Content Placeholder 3" (right) by default.
% You can rename the placeholders according to your choice and use the new
% names instead.
replace(slide1, "Content Placeholder 2", picLeft);
replace(slide1, "Content Placeholder 3", picRight);
close(ppt);
Additionally, you can also create a new custom layout in Slide Master and design it exactly the way you need. You can resize the placeholders in Slide Master so they match the exact image sizes or layout you want.
For more information, refer to the following documentations:
Hope this helps!

추가 답변 (0개)

제품

릴리스

R2024b

질문:

2026년 2월 12일

댓글:

2026년 2월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by