Excel images

GemBox.Spreadsheet represents images with ExcelPicture and it supports various formats like PNG, JPEG, EXIF, GIF, TIFF, ISO, SVG, EMF, and WMF. You can add or remove images from your Excel file using the ExcelWorksheet.Pictures collection.

In PDF files, the SVG images are rendered as vector graphics, resulting in smaller file size and better quality than bitmap images.

In XLS files, only PNG, JPEG, and EMF images are supported.

The following example shows how you can add images in different formats using various types of positioning.

Adding images of various formats and positions to an Excel worksheet from C# and VB.NET
Screenshot of Excel images
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = new ExcelFile();
        var worksheet = workbook.Worksheets.Add("Images");

        // Add small BMP image with specified rectangle position.
        worksheet.Pictures.Add("%#SmallImage.bmp%", 50, 50, 48, 48, LengthUnit.Pixel);

        // Add large JPG image with specified top-left cell.
        worksheet.Pictures.Add("%#FragonardReader.jpg%", "B9");

        // Add PNG image with specified top-left and bottom-right cells.
        worksheet.Pictures.Add("%#Dices.png%", "J16", "K20");

        // Add GIF image using anchors.
        var picture = worksheet.Pictures.Add("%#Zahnrad.gif%",
            new AnchorCell(worksheet.Columns[9], worksheet.Rows[21], 100000, 100000),
            new AnchorCell(worksheet.Columns[10], worksheet.Rows[23], 50000, 50000));

        // Set picture's position mode.
        picture.Position.Mode = PositioningMode.Move;

        // Add SVG image with specified top-left cell and size.
        picture = worksheet.Pictures.Add("%#Graphics1.svg%", "J9", 250, 100, LengthUnit.Pixel);

        // Set picture's metadata.
        picture.Metadata.Name = "SVG Image";

        workbook.Save("Images.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = New ExcelFile
        Dim worksheet = workbook.Worksheets.Add("Images")

        ' Add small BMP image with specified rectangle position.
        worksheet.Pictures.Add("%#SmallImage.bmp%", 50, 50, 48, 48, LengthUnit.Pixel)

        ' Add large JPG image with specified top-left cell.
        worksheet.Pictures.Add("%#FragonardReader.jpg%", "B9")

        ' Add PNG image with specified top-left and bottom-right cells.
        worksheet.Pictures.Add("%#Dices.png%", "J16", "K20")

        ' Add GIF image using anchors.
        Dim picture = worksheet.Pictures.Add("%#Zahnrad.gif%",
            New AnchorCell(worksheet.Columns(9), worksheet.Rows(21), 100000, 100000),
            New AnchorCell(worksheet.Columns(10), worksheet.Rows(23), 50000, 50000))

        ' Set picture's position mode.
        picture.Position.Mode = PositioningMode.Move

        ' Add SVG image with specified top-left cell and size.
        picture = worksheet.Pictures.Add("%#Graphics1.svg%", "J9", 250, 100, LengthUnit.Pixel)

        ' Set picture's metadata.
        picture.Metadata.Name = "SVG Image"

        workbook.Save("Images.%OutputFileType%")

    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.