Strange Error while writing to powerpoint file : "createInputStream failed:"
조회 수: 17 (최근 30일)
이전 댓글 표시
Hi All
in my following code, I am getting a strange error and don't know where it is referring to. I am trying to create a subplot from the function I created and then use its image to write to a ppt file.
Error :
Error : "createInputStream failed:"
my code :
content = dir('*.xlsx');
content([content.isdir]) = [];
files = cell(size(content));
for fi = 1:numel(files)
[~, files{fi}] = fileparts(content(fi).name);
end
for fn=1:numel(files)
ff= xlsread(strcat(files{fn},'.xlsx'));
t = ff(:,1);
motiont=ff;
maxlim=max(max(motiont(:,2:7)))
minlim=min(min(motiont(:,2:7)))
directory=pwd
pptpop(motiont,minlim,maxlim,files{fn})
end
function pptpop(motion6t,minlim, maxlim,filename)
import mlreportgen.ppt.*;
images = {};
slidesFile = 'Report.pptx';
pre = Presentation(slidesFile);
slide = add(pre, 'Title Slide');
replace(slide, 'Title', 'ttt');
replace(slide, 'Subtitle', '111');
slide = add(pre, 'Title and Content');
replace(slide, 'Title', 'Contents');
slide = add(pre, 'Title and Content');
replace(slide, 'Title', 'US Census data from 1900 to 2000');
% Time interval
% Plot
myfigure(motion6t,minlim, maxlim,filename)
img = printPlot('plot1');
% Replace the Content placeholder by the plot
replace(slide, 'Content', Picture(img));
images = [images {img}]; %#ok<*NASGU>
%% Finally, close the presentation and open it in Windows
close(pre);
if ispc
winopen(pre.OutputPath);
end
% Closing the presentation causes the images needed for the
% presentation to be copied into it. So we can now delete them.
for i = 1:length(images)
delete(images{i});
end
% Convert figure to the specified image type.
exportgraphics(gcf, imgname)
% Delete plot figure window.
delete(gcf);
function imgname = printPlot(name)
import mlreportgen.ppt.*;
% Select an appropriate image type, depending
% on the platform.
if ~ispc
imgtype = '-dpng';
imgname= [name '.png'];
else
% This Microsoft-specific vector graphics format
% can yield better quality images in Word documents.
imgtype = '-dmeta';
imgname = [name '.emf'];
end
end
function myfigure(motion6t,minlim, maxlim,filename)
f = figure('visible', 'off');
fsize=12;
lw= 0.7
subplot(611);
plot(motion6t(:,1),motion6t(:,2),'LineWidth',lw)
grid;
ylabel('Tx (mm)');
title(filename);
ax1=gca;
ax1.FontSize=fsize;
subplot(612);
plot(motion6t(:,1),motion6t(:,3),'LineWidth',lw);
grid;
ylabel('Ty (mm)');
ax1=gca;
ax1.FontSize=fsize;
subplot(613);
plot(motion6t(:,1),motion6t(:,4),'LineWidth',lw);
grid;
ylabel('Tz (mm)');
ax1=gca;
ax1.FontSize=fsize;
subplot(614);
plot(motion6t(:,1),motion6t(:,5),'LineWidth',lw);
grid;
ylabel('Rx (deg)');
ax1=gca;
ax1.FontSize=fsize;
subplot(615);
plot(motion6t(:,1),motion6t(:,6),'LineWidth',lw);
grid;
ylabel('Ry (deg)');
ax1=gca;
ax1.FontSize=fsize;
subplot(616);
plot(motion6t(:,1),motion6t(:,7),'LineWidth',lw);
grid;
ylabel('Rz (deg)');
xlabel('Time (sec)');
ax1=gca;
ax1.FontSize=fsize;
for kk =1:6
subplot(6,1,kk)
ylim([minlim, maxlim]);
end
% fname=strcat(filename,'.jpg');
% savefig(f,fname)
set(gcf, 'Position', [100, 100, 1000, 800])
% saveas(gcf,strcat(filename,'.jpg'))
end
end
댓글 수: 4
Ricardo Zetina
2021년 1월 6일
Hey, I had a similar error ("createInputStream failed:" when running the close command).
For me the issue was solved by changing directory to the save file location. I was using absolute paths, but still needed to be in the same folder. Maybe give that a try.
답변 (1개)
Robin
2024년 3월 6일
What happens if you move
exportgraphics(gcf, imgname)
above the line that closes the presentation?
Indeed, you should close the presentation first and then close the figures.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!