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 GoUse 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.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
workSheet.InsertImage("logo.png", 1, 1, 3, 3); workSheet.RemoveImage(1); var firstImage = workSheet.Images[0];C# -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
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.
This odd-number sequence is crucial when referencing specific images for extraction or removal operations later.
using 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.
using 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.
using 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 worksheets using IronXL?
You can use the `InsertImage` method in IronXL to add images to Excel worksheets. This method supports various image formats like JPG, PNG, GIF, and TIFF, allowing you to specify the top-left and bottom-right corners for precise placement.
Can IronXL remove images from Excel files?
Yes, IronXL enables you to remove images using the `RemoveImage` method. You'll need to reference the image's unique ID, which IronXL assigns in an odd-number sequence, to remove it from the worksheet.
How can I extract images from an Excel worksheet with IronXL?
To extract images, access the `Images` property of the worksheet in IronXL. This gives you a list of images that you can export, resize, or retrieve position data for, thus allowing for extensive manipulation.
What image formats are supported when adding images to Excel in IronXL?
IronXL supports a variety of image formats for insertion, including JPG, JPEG, BMP, PNG, GIF, and TIFF, ensuring compatibility with most standard image files.
How does IronXL assign IDs to images in Excel worksheets?
IronXL assigns a unique ID to each image in an odd-numbered sequence, such as 1, 3, 5, etc. These IDs are crucial for performing operations like extraction or removal.
Is it possible to programmatically resize images in Excel using IronXL?
Yes, you can programmatically resize images using the functionality provided by IronXL. This can be done during extraction by accessing the image's properties and adjusting the size.
Does IronXL require Excel Interop to manage images in Excel files?
No, IronXL does not require Excel Interop. It fully supports adding, extracting, and removing images from Excel files programmatically, eliminating the need for Microsoft Office dependencies.
How can I retain the position of images when extracting them from Excel files with IronXL?
When extracting images with IronXL, you can retrieve their position data, including row and column indices, to preserve layout and positioning information.
Why would I use IronXL for image manipulation in Excel workbooks?
IronXL simplifies image manipulation in Excel, allowing for consistent placement, extraction, and removal of images programmatically without reliance on manual processes or Excel Interop.
Can IronXL handle images in password-protected Excel files?
Yes, IronXL can work with password-protected Excel files. You may need to manage worksheet-level operations to ensure compatibility with image manipulation.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.