Reputation: 23
I would like to directly delete all the figures in an excel file from MATLAB. I can select all the figures using activex but I cant' figure out a way to delete them.
My code:
filename_out = 'Libraries\Documents\TEST.xlsx'; % filename
Excel = actxserver('Excel.Application'); % open the connection
set(Excel,'Visible',1);
Excel.Workbooks.Open(filename_out); % open excel file
worksheets = Excel.sheets;
numSheets = worksheets.Count; % count the number of sheets
for s = 1 : numSheets % do a loop for all sheets
worksheets.Item(s).Shapes.SelectAll; % select the figure
% How to delete selection? *
end
Thanks for any help!
Upvotes: 1
Views: 421
Reputation: 24127
Within your loop, do something like
myshapes = worksheets.Item(s).Shapes;
for j = myshapes.Count:-1:1
myshapes.Item(j).Delete
end
Note that we're counting down from myshapes.Count
to 1, as the count goes down each time you remove one.
Upvotes: 1