Filter löschen
Filter löschen

Delete Images from Excel Sheet

2 Ansichten (letzte 30 Tage)
Emanuel  Arth
Emanuel Arth am 4 Mai 2017
Hi,
I have a Problem with deleting figures from a Excel sheet. I'm printing some figures in my active excel sheet. But when I want to do this again on the same page I first need to delete the figures I set there before.
My working code (without the delete function):
sheet=Page %Indicates the Page on which I want to set the figure
Excel = actxserver ('Excel.Application');
File=Dateiname;
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
end
invoke(Excel.Workbooks,'Open',File);
Sheets = Excel.ActiveWorkBook.Sheets;
SheetNo = get(Sheets, 'Item', sheet);
SheetNo.Activate;
xls=Excel.ActiveSheet
print (figure1,'-dbitmap'); xls.Range('I85').PasteSpecial; %Prints my figure on the page
xls.Shapes.Item(1).Height=(2334/7);
invoke(Excel.ActiveWorkbook,'Save')
Excel.Quit
Excel.delete
clear Excel
I run this code 4 times (I'm always printing a different figure). So I have 4 figures on my active Excel sheet. But when I run this code again I don't want to add new figures to the already existing - I want to delete the figures that are on this sheet and then add the new ones.
I've found a smiliar code, but it does not work for me. I tried to set it before I print the new figures on my sheet. I only want to set the delete Loop in my first function to delete all figures and then set the first figure...then run the second function and print the second figure ...
This is the code I've found:
....
SheetNo.Activate;
Sheets.Item('Graphs').Activate;
ActiveSheets = Excel.Activesheet;
myshapes = ActiveSheets.Shapes;
for j = myshapes.Count:-1:1
myshapes.Item(j).Delete
end
xls=Excel.ActiveSheet
...
I have to admit that I have other data on the Excel sheet that should not be deletet. Therefore deleting the whole sheet is no option for me. Can you help me ?
Thank you !
Emanuel

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by