Home » excel » c# – how to delete an image on a sheet

c# – how to delete an image on a sheet

Posted by: admin April 23, 2020 Leave a comment

Questions:

hi let’s say i have images on my excel worksheet, how is it possible to delete/remove them from the sheet using c#,

following code gives me exception

        Excel.Worksheet ws = Globals.ThisAddIn.GetActiveWorksheet();
        foreach (Excel.Shape sh in ws.Shapes)
        {
            sh.Delete();
        }

thanks!

How to&Answers:

never mind, i forgot that my sheet was protected,

    Excel.Worksheet ws = Globals.ThisAddIn.GetActiveWorksheet();
    ws.Unprotect("PASSWORD");
    foreach (Excel.Shape sh in ws.Shapes)
    {
        sh.Delete();
    }

it works fine!