Last Saved .PNG uploaded on all PPT slides

조회 수: 2 (최근 30일)
Zack Morris
Zack Morris 2023년 12월 4일
댓글: Zack Morris 2023년 12월 6일
For some reason my code would only upload my last saved .png file on all my PPT generated slides. I don't have this issue if i make a for loop for each image but that'd be too tedious. My code is supposed to upload each saved plot onto separate PPT slides.
Does the issue lie in the replace() function or the for loop statement? I labeled below
The code:
a = fileLength; % fileLength = 6 in this example
for j = 3:length(a) %The issue may lie here
imgFIG = openfig(strcat(fileList(j).folder,'\',fileList(j).name));
saveas(imgFIG,'plot6.png');
imgPNG = imread('plot6.png');
imgPNG2 = imresize(imgPNG, 1.5);
imwrite(imgPNG2,'plot7.png')
imgPNG3 = Picture('plot7.png');
fName = fileList(j).name;
z = fName(27:28);
dataSlides = add(ppt,'Title and Content');
newTitle = strcat('Step', {' '}, z,' Simulations');
replace(dataSlides,'Title', newTitle);
replace(dataSlides,'Content', imgPNG3); %The issue may lie here
clearvars -except j pL ppt directory fileList dirSize a
end

답변 (1개)

Image Analyst
Image Analyst 2023년 12월 4일
What does this line do:
dataSlides = add(ppt,'Title and Content');
What is ppt? I'd use ActiveX if you're using Windows.
Why are you calling clearvars? I'd get rid of that. It's not necessary.
And if
a = fileLength; % fileLength = 6 in this example
then
1:length(a)
so the loop only happens once because length(6) = 1. The length of a scalar is just one value. Try
for j = 3: a % For j = 3, 4, 5, and 6
  댓글 수: 5
Image Analyst
Image Analyst 2023년 12월 5일
I don't think I can help more unless I have the full code, like where you instantiate ppt.
Can you use ActiveX (i.e. are you on Windows and willing to use it)?
Zack Morris
Zack Morris 2023년 12월 6일
Thank you. Using what you said for j and the bottom 2 lines fixed the photo issue on each PPT slide.
for j = 1:a
imgFIG = openfig(strcat(fileList(j).folder,'\',fileList(j).name));
saveas(imgFIG,['plot' num2str(j) '.png']);
imgPNG = Picture(['plot' num2str(j) '.png']);
%imgPNG = imread('plot.png');
%imgPNG2 = imresize(imgPNG, 1.5);
%imwrite(imgPNG2,'plot2.png')
%imgPNG3 = Picture('plot2.png');
fName = fileList(j).name;
z = fName(27:28);
dataSlides = add(ppt,'Title and Content');
newTitle = strcat('Step', {' '}, z,' Simulations');
replace(dataSlides,'Title', newTitle);
replace(dataSlides,'Content', imgPNG);
end
My new issue is resizing the images. I tried using the imresize command with imgPNG but no result. Any assistance?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Update PowerPoint Presentation Content에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by