How to Add, Extract, and Remove Images in Excel Using C#
IronXL enables C# developers to programmatically insert images into Excel worksheets, extract existing images with their properties, and remove unwanted images using simple API methods without Excel Interop dependencies. This functionality is essential when creating Excel files in .NET that require visual elements like company logos, product images, or data visualization graphics.
Adding images enriches data with relevant graphics or illustrations. Removing images simplifies content editing and organization. Extracting images allows repurposing them in other documents or applications and updating existing images. These features provide complete control over image manipulation within Excel workbooks.
Quickstart: Insert, Extract & Remove Images in One Go
Use IronXL's intuitive API to add, get, and delete images from worksheets in just a few lines. This example shows how to insert an image, access it via the Images collection, and remove it—all without touching Interop.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
workSheet.InsertImage("logo.png", 1, 1, 3, 3); workSheet.RemoveImage(1); var firstImage = workSheet.Images[0];Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download the C# library to insert, extract, and remove images from spreadsheets
- Import an existing Excel file or create a new one
- Use the
InsertImagemethod to insert an image into the worksheet - Access the Images property to extract images and their information
- Supply the ID to the
RemoveImagemethod to remove the image
How Do I Add Images to Excel Worksheets?
To insert an image into a spreadsheet, use the InsertImage method, which supports various image types including JPG/JPEG, BMP, PNG, GIF, and TIFF. This capability is particularly useful when you need to create Excel charts in C# and supplement them with additional visual elements. Specify the top-left and bottom-right corners of the image to determine its dimensions, calculated by subtracting the column and row values.
The method signature requires five parameters: the image file path, and four integers representing the starting column, starting row, ending column, and ending row. The image will stretch or compress to fit within the defined cell range. For example:
- For a 1x1 image size:
worksheet.InsertImage("image.gif", 5, 1, 6, 2);
- For a 2x2 image size:
worksheet.InsertImage("image.gif", 5, 1, 7, 3);
When working with images in Excel, understand how IronXL manages them internally. Each inserted image receives a unique ID that follows a specific pattern.
:path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-insert.csusing IronXL;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Insert images
workSheet.InsertImage("ironpdf.jpg", 2, 2, 4, 4);
workSheet.InsertImage("ironpdfIcon.png", 2, 6, 4, 8);
workBook.SaveAs("insertImages.xlsx");Imports IronXL
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Insert images
workSheet.InsertImage("ironpdf.jpg", 2, 2, 4, 4)
workSheet.InsertImage("ironpdfIcon.png", 2, 6, 4, 8)
workBook.SaveAs("insertImages.xlsx")The InsertImage method provides flexibility in positioning and sizing images within your worksheet. Unlike manual image insertion in Excel, programmatic insertion ensures consistent placement across multiple files, making it ideal for generating reports or documents that require standardized formatting. This approach is particularly beneficial when working with Excel in C# without Interop, as it eliminates dependencies on Microsoft Office installations.
What Does the Inserted Image Look Like in Excel?

How Can I Extract Images From Excel Files?
To extract images from the selected worksheet, access the Images property, which provides a list of all images contained within the sheet. This feature is essential when you need to load Excel files without Interop and process their embedded visual content. From this list, you can perform various operations such as exporting, resizing, retrieving positions, and obtaining the byte data of each image. The image IDs follow an odd-numbered pattern, incrementing in the sequence of 1, 3, 5, 7, and so on.
The extraction process provides comprehensive access to image properties and data, enabling developers to:
- Export images to various formats (PNG, JPEG, BMP, etc.)
- Retrieve image positioning information for layout preservation
- Access raw byte data for custom processing or storage
- Resize images programmatically without external image processing libraries
This functionality proves invaluable when migrating content between different document formats or when building systems that need to catalog and manage visual assets from Excel files. The ability to extract images programmatically also supports automated quality control processes where images need validation or processing according to specific business rules.
:path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-extract.csusing IronSoftware.Drawing;
using IronXL;
using IronXL.Drawing;
using System;
using System.Collections.Generic;
WorkBook workBook = WorkBook.Load("insertImages.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Retreive images
List<IronXL.Drawing.Images.IImage> images = workSheet.Images;
// Select each image
foreach (IronXL.Drawing.Images.IImage image in images)
{
// Save the image
AnyBitmap anyBitmap = image.ToAnyBitmap();
anyBitmap.SaveAs($"{image.Id}.png");
// Resize the image
image.Resize(1,3);
// Retrieve image position
Position position = image.Position;
Console.WriteLine("top row index: " + position.TopRowIndex);
Console.WriteLine("bottom row index: " + position.BottomRowIndex);
// Retrieve byte data
byte[] imageByte = image.Data;
}
workBook.SaveAs("resizeImage.xlsx");Imports IronSoftware.Drawing
Imports IronXL
Imports IronXL.Drawing
Imports System
Imports System.Collections.Generic
Private workBook As WorkBook = WorkBook.Load("insertImages.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Retreive images
Private images As List(Of IronXL.Drawing.Images.IImage) = workSheet.Images
' Select each image
For Each image As IronXL.Drawing.Images.IImage In images
' Save the image
Dim anyBitmap As AnyBitmap = image.ToAnyBitmap()
anyBitmap.SaveAs($"{image.Id}.png")
' Resize the image
image.Resize(1,3)
' Retrieve image position
Dim position As Position = image.Position
Console.WriteLine("top row index: " & position.TopRowIndex)
Console.WriteLine("bottom row index: " & position.BottomRowIndex)
' Retrieve byte data
Dim imageByte() As Byte = image.Data
Next image
workBook.SaveAs("resizeImage.xlsx")
Extracted Images

Image Size
How Do I Remove Images From Excel Worksheets?
Following the extract images example, you can easily remove any inserted image using its corresponding index number. Pass the image's ID number to the RemoveImage method to remove it from the worksheet. This operation is particularly useful when you need to edit Excel files in C# to clean up unwanted visual elements or prepare documents for different audiences.
The removal process is straightforward but requires understanding the image ID system. Since IronXL assigns IDs in an odd-number sequence (1, 3, 5, 7...), track these IDs when managing multiple images. Consider implementing a mapping system in your application to associate meaningful names with image IDs for easier management.
:path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-remove.csusing IronXL;
WorkBook workBook = WorkBook.Load("insertImages.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Remove image
workSheet.RemoveImage(3);
workBook.SaveAs("removeImage.xlsx");Imports IronXL
Private workBook As WorkBook = WorkBook.Load("insertImages.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Remove image
workSheet.RemoveImage(3)
workBook.SaveAs("removeImage.xlsx")For more complex scenarios involving multiple worksheets and images, explore managing worksheets to understand how image operations interact with worksheet-level operations. Additionally, when working with protected Excel files, refer to our guide on protecting Excel files to understand how image operations work with password-protected workbooks.
Frequently Asked Questions
How do I add images to Excel spreadsheets programmatically in C#?
IronXL provides the InsertImage method to add images to Excel worksheets. Simply specify the image file path and the cell range coordinates (top-left and bottom-right corners) where you want the image to appear. IronXL supports various image formats including JPG/JPEG, BMP, PNG, GIF, and TIFF.
What image formats are supported when inserting images into Excel?
IronXL supports multiple image formats for insertion into Excel worksheets, including JPG/JPEG, BMP, PNG, GIF, and TIFF. This flexibility allows you to work with various image types commonly used in business documents and data visualization.
How do I extract existing images from an Excel worksheet?
You can extract images from Excel worksheets using IronXL's Images collection property. Access worksheet.Images[index] to retrieve specific images along with their properties and metadata, allowing you to repurpose them in other documents or applications.
Can I remove images from Excel files programmatically?
Yes, IronXL provides the RemoveImage method to delete images from worksheets. Simply supply the image ID to remove specific images, giving you complete control over image management without requiring Excel Interop.
How do I specify the size and position of an inserted image?
When using IronXL's InsertImage method, you specify four coordinates: starting column, starting row, ending column, and ending row. The image will automatically stretch or compress to fit within the defined cell range. For example, InsertImage("image.gif", 5, 1, 6, 2) creates a 1x1 image size.
Do I need Microsoft Excel installed to manipulate images in spreadsheets?
No, IronXL operates independently without requiring Microsoft Excel or Excel Interop dependencies. You can add, extract, and remove images from Excel files programmatically using just the IronXL library in your .NET application.






