Excel Images

Following example shows how to add images in different formats to ExcelWorksheet using various types of positioning.

Excel Images Screenshot
using System;
using GemBox.Spreadsheet;

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

        ExcelFile ef = new ExcelFile();
        ExcelWorksheet ws = ef.Worksheets.Add("Images");

        ws.Cells[0, 0].Value = "Image examples:";

        // Small BMP added by using rectangle.
        ws.Pictures.Add("%#SmallImage.bmp%", 50, 50, 48, 48, LengthUnit.Pixel);

        // Large JPG added by using one anchor.
        ws.Pictures.Add("%#FragonardReader.jpg%", "B9");

        // PNG added by using two anchors.
        ws.Pictures.Add("%#Dices.png%", "J16", "K20");

        // GIF added by using anchors. Notice that animation is lost in MS Excel.
        ws.Pictures.Add("%#Zahnrad.gif%",
                    new AnchorCell(ws.Columns[9], ws.Rows[21], 100000, 100000),
                    new AnchorCell(ws.Columns[10], ws.Rows[23], 50000, 50000)).Position.Mode = PositioningMode.Move;

        // WMF added by using one anchor and size.
        ws.Pictures.Add("%#Graphics1.wmf%", "J9", 250, 100, LengthUnit.Pixel).Position.Mode = PositioningMode.FreeFloating;

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

Module Program

    Sub Main()

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

        Dim ef As ExcelFile = New ExcelFile
        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Images")

        ws.Cells(0, 0).Value = "Image examples:"

        ' Small BMP added by using rectangle.
        ws.Pictures.Add("%#SmallImage.bmp%", 50, 50, 48, 48, LengthUnit.Pixel)

        ' Large JPG added by using one anchor.
        ws.Pictures.Add("%#FragonardReader.jpg%", "B9")

        ' PNG added by using two anchors.
        ws.Pictures.Add("%#Dices.png%", "J16", "K20")

        ' GIF added by using anchors. Notice that animation is lost in MS Excel.
        ws.Pictures.Add("%#Zahnrad.gif%",
                        New AnchorCell(ws.Columns(9), ws.Rows(21), 100000, 100000),
                        New AnchorCell(ws.Columns(10), ws.Rows(23), 50000, 50000)).Position.Mode = PositioningMode.Move

        ' WMF added by using one anchor and size.
        ws.Pictures.Add("%#Graphics1.wmf%", "J9", 250, 100, LengthUnit.Pixel).Position.Mode = PositioningMode.FreeFloating

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

    End Sub

End Module

Check next example or download examples from GitHub.