【问题标题】:Delete Excel Figures from Matlab从 Matlab 中删除 Excel 图形
【发布时间】:2013-09-23 12:14:15
【问题描述】:

我想直接从 MATLAB 中删除 excel 文件中的所有数字。我可以使用 activex 选择所有数字,但我无法找到删除它们的方法。

我的代码:

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

感谢您的帮助!

【问题讨论】:

    标签: matlab excel activex vba


    【解决方案1】:

    在你的循环中,做类似的事情

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

    请注意,我们正在从 myshapes.Count 倒数到 1,因为每次您删除一个计数都会减少。

    【讨论】:

    • 如果你想要最终的完整解决方案:worksheets = Excel.sheets; numSheets = worksheets.Count;对于 s = 1 : numSheets myshapes = worksheets.Item(s).Shapes; for j = myshapes.Count:-1:1 myshapes.Item(j).Delete end end
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    相关资源
    最近更新 更多