Editing PowerPoint While It is Open

10 visualizaciones (últimos 30 días)
Ephraim Bryski
Ephraim Bryski el 6 de Jul. de 2019
Comentada: J G el 25 de Nov. de 2020
Hi. I'm trying to write code which will add or edit images in a powerpoint. The only problem I have now is that I can only edit it while the powerpoint window is closed. If it is open, the following error appears:
Error using mlreportgen.ppt.Presentation/find
Cannot open file. C:/Users/me/folder/my_powerpoint.pptx
Error in add_to_ppt (line 5)
previous_content=find(slides,name);
Does anyone know a way of editing the powerpoint while it is open? Thanks in advance!
Here is the function I'm using:
function add_to_ppt(name,content)
import mlreportgen.ppt.*;
slides = Presentation('C:\Users\me\folder\my_powerpoint.pptx','C:\Users\me\folder\my_powerpoint.pptx');
previous_content=find(slides,name);
image=Picture(content);
image.Name=name;
if isempty(previous_content)
image.X='0in';
image.Y='0in';
image.Height='7.5in';
image.Width='13.33in';
new_slide=add(slides,'Blank');
add(new_slide,image);
else
image.X=previous_content.X;
image.Y=previous_content.Y;
image.Height=previous_content.Height;
image.Width=previous_content.Width;
replace(previous_content,image);
end
close(slides);
end
  1 comentario
Ashwini  More
Ashwini More el 4 de Feb. de 2020
Hi,
I am working on adding images to existing powerpoint with matlab code. I think your code will help me to do my work.
After reading your code, I dont get how can I add specific image to specific slide from following code:
previous_content=find(slides,name);
image=Picture(content);
image.Name=name;
So can you please help me to clear my doubt?
Any help would be appreciated!

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 6 de Jul. de 2019
When a file is open in powerpoint, powerpoint locks it so no other program can edit it. This is why you get an error when trying to open the file.
Instead of using mlreport to edit the file, you could talk directly to powerpoint and send it instructions to modify the file. The downside of this is you can't use the report generator anymore, you'll have to do everything yourself. You would have to use actxGetRunningServer to find the open powerpoint instance and then use the powerpoint object model to do what you want. Not impossible but a lot of work if you're not familiar with it.
Frankly, the simplest thing to do is to ensure that you've closed the file before editing with matlab. This would also ensure that if there were some unsaved changed in the powerpoint file, they are actually saved before the edition with matlab.
  2 comentarios
Ephraim Bryski
Ephraim Bryski el 6 de Jul. de 2019
Thank you! Alright, I think I'll stick with this method then.
J G
J G el 25 de Nov. de 2020
Just commenting here for the record, the File Exchange function "toPPT" by jrichter24 allows for programmatic PowerPoint slide creation and editing while PowerPoint is open.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by