%Create a graph
x = 0:.1:2*pi;
y = sin(x);
f = plot(x,y);
print -djpeg -f thefigfile
%Start Excel
excl = actxserver('excel.application');
set(excl,'visible',1);
wkbk = excl.Workbooks;
exclFile = wkbk.Open('C:\DataToExcel.xls');
rptSheet = exclFile.Sheets.Item('Sheet1');
imgrng = rptSheet.Range('I20')
imgrng.Select
%AddPicture(shps, 'thefigfile.jpg')
shps = rptSheet.Shapes;
shps.AddPicture('thefigfile.jpg');
%Quit Excel
excl.Quit
The error I get is "??? No method 'AddPicture' with matching signature found for class 'Interface.Microsoft_Excel_12.0_Object_Library.Shapes'."
Error in ==> SendToExcel at 18
shps.AddPicture('thefigfile.jpg');
Help>
Jeff
However here it seems to say that it should work.
http://msdn.microsoft.com/en-us/library/bb209605.aspx
I don't have an answer but the answer is probably buried in that MS
documentation somewhere, although it could take a while to find
because the documentation is so deep and covers so many versions.
exl2 = actxserver('excel.application');
exlWkbk2 = exl2.Workbooks;
wb = invoke(exlWkbk2,'Add');
graphSheet = invoke(wb.Sheets,'Add');
Shapes = graphSheet.Shapes;
function saveButtonCallback(src,evt)
tempfig = figure('Visible','off','PaperPositionMode','auto');
tempfigfile = [tempname '.png'];
ah = findobj(f,'type','axes');
copyobj(ah,tempfig) % Copy both graph axes and legend axes
print(tempfig,'-dpng',tempfigfile);
Shapes.AddPicture(tempfigfile,0,1,50,18,300,235);
exl2.visible = 1;
end
I did change a couple bits of the code, but nothing that I thought would change the functionality. I guess I can run the entire example and see what happens. Just not sure why this isn't working.
"Jeff " <jag...@yahoo.com> wrote in message
news:iavsm3$88r$1...@fred.mathworks.com...
The big change I can see that you made that WOULD change the functionality:
%AddPicture(shps, 'thefigfile.jpg')
shps = rptSheet.Shapes;
shps.AddPicture('thefigfile.jpg');
Note that in the code from the User Guide, the AddPicture method is being
called with seven input arguments. It's entirely possible (I'm not familiar
enough with Microsoft Excel's COM interface to know for certain) that
AddPicture _requires_ all seven inputs. Check the documentation on
Microsoft's website to which ImageAnalyst directed you to determine what
those inputs represent and how many of them are required.
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Thanks for the input. I did try using the same 7 values - albeit with no idea od what they represent. I'm guilty of not seriously looking at the definition of those parameters. I guess I'll have a look and see if I can figure (no punintended) something out.
Jeff
Jeff