Strange Error while writing to powerpoint file : "createInputStream failed:"

34 views (last 30 days)
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 Comments
Ricardo Zetina
Ricardo Zetina on 6 Jan 2021
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.

Sign in to comment.

Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!