2013-09-23 49 views
1

我想直接从MATLAB中删除excel文件中的所有数字。我可以使用activex选择所有的数字,但我不能'找出一种方法来删除它们。从Matlab中删除Excel数字

我的代码:

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 

感谢您的帮助!

回答

1

在你的循环,这样做

myshapes = worksheets.Item(s).Shapes; 
for j = myshapes.Count:-1:1 
    myshapes.Item(j).Delete 
end 

请注意,我们从myshapes.Count倒计时1,作为计数下降每删除一次。

+0

谢谢你,完美的作品! – cV17

+0

如果您想要最终的完整解决方案: 工作表= Excel.sheets; numSheets = worksheets.Count; for s = 1:numSheets myshapes = worksheets.Item(s).Shapes; for j = myshapes.Count:-1:1 myshapes.Item(j).Delete end end – cV17