how to add image in determined excel cell in matlab??
18 次查看(过去 30 天)
显示 更早的评论
hi, i want add small image in determined cell using matlab
0 个评论
回答(1 个)
Image Analyst
2015-2-21
What is a "determined" cell in Excel? How is that different than just a regular, normal cell? Anyway, cells hold numbers, not images so I'm not sure what you're thinking of. You can place an image onto a worksheet as a graphical element though, but you can't add it to anything.
4 个评论
Manoj Yasaswi
2018-1-24
Can you please post a sample code to display any image, for example, cameraman.tif in an excel cell using xlswrite() command.
Image Analyst
2018-1-24
See this snippet for how to paste an image onto an Excel Worksheet
%==========================================================================================================================
% Adapted from https://www.mathworks.com/matlabcentral/answers/91547-how-do-i-insert-a-matlab-figure-into-an-excel-workbook-through-activex
function PasteFigureIntoExcel(Excel, imageFullFileName)
try
% Use whatever sheet is active at the moment. This should be setup in advance of calling this function.
currentSheet = Excel.ActiveSheet;
% Get a handle to Shapes for Sheet 1
Shapes = currentSheet.Shapes;
% Add image by importing one from an image file on disk.
% Syntax:
% Shapes.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
% If width and height are -1, then it uses the native image dimensions.
Shapes.AddPicture(imageFullFileName, 0, 1, 350, 60, -1, -1);
% Delete the temporary image file.
% delete(imageFullFileName);
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
WarnUser(errorMessage);
end
return;
You first need to get the Excel server as an activeX object and you do that like this:
try
% See if there is an existing instance of Excel running.
% If Excel is NOT running, this will throw an error and send us to the catch block below.
Excel = actxGetRunningServer('Excel.Application');
% If there was no error, then we were able to connect to it.
catch
% No instance of Excel is currently running. Create a new one.
% Normally you'll get here (because Excel is not usually running when you run this).
Excel = actxserver('Excel.Application');
end
invoke(Excel.Workbooks, 'Open', xlsFullFileName);
Excel.visible = true; % Make Excel appear so we can see it, otherwise it is hidden.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!