Delete Images from Excel Worksheet in C#

This article demonstrates how to delete images from an excel worksheet using Spire.XLS component and C#. Below is the screenshot of the sample file we used for demonstration:

Delete Images from Excel Worksheet in C#

Detail steps:

Step 1: Initialize an object of Workbook class and load the excel file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Delete all images from the worksheet.

for (int i = sheet.Pictures.Count-1; i >= 0; i--)
{
    sheet.Pictures[i].Remove();
}

Step 4: Save the file.

workbook.SaveToFile("DeleteImages.xlsx", ExcelVersion.Version2013);

Output:

Delete Images from Excel Worksheet in C#

Full code:

using Spire.Xls;

namespace DeleteImages
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Input.xlsx");

            Worksheet sheet = workbook.Worksheets[0];

            for (int i = sheet.Pictures.Count-1; i >= 0; i--)
            {
                sheet.Pictures[i].Remove();
            }

            workbook.SaveToFile("DeleteImages.xlsx", ExcelVersion.Version2013);
        }
    }
}