How to delete figure in an excel file

3 ビュー (過去 30 日間)
Christe  Antoine
Christe Antoine 2013 年 9 月 16 日
編集済み: Walter Roberson 2018 年 8 月 13 日
Hi,
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!

採用された回答

Christe  Antoine
Christe Antoine 2013 年 9 月 23 日
編集済み: Walter Roberson 2018 年 8 月 13 日
I finally found a solution:
worksheets = Excel.sheets;
numSheets = worksheets.Count;
for s = 1 : numSheets % Delete all shapes in Excel
myshapes = worksheets.Item(s).Shapes;
for j = myshapes.Count:-1:1
myshapes.Item(j).Delete
end
end

その他の回答 (2 件)

Image Analyst
Image Analyst 2013 年 9 月 16 日
Go to the sheet. Start recording a macro. Then do your operations (deleting things, etc.). Then stop recording and look at the macro source code and see what code Excel put in there. Then transfer that code to your MATLAB program.
  1 件のコメント
Image Analyst
Image Analyst 2013 年 9 月 17 日
So, did that work for you?

サインインしてコメントする。


Christe  Antoine
Christe Antoine 2013 年 9 月 17 日
No, I already tried to do something like that. The excel macro give me something like:
ActiveSheet.Shapes.Range(Array("Picture11","Picture12").Select
Selection.Delete
I have no problem with the figure selection in MATLAB (worksheets.Item(s).Shapes.SelectAll), but Selection.Delete give me an error:
"Undefined variable "Selection" or function "Selection.Delete".
Any other idea?
Thank for your help!

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by