Thursday, 20 January 2011 10:33

Insert Image in Excel in C#, VB.NET

Written by  Administrator
Rate this item
(0 votes)

Users are allowed to insert image in Excel files. With image, the appearance of Excel file will be more beautiful. Besides decorating, some images are related to data information in Excel. For example, the image will be a chart. These images can make readers learn data information more clearly. This guide will show an easy method to insert image in Excel with C#, VB.NET

Spire.XLS for .NET, a professional component to operating Excel files, enables users to insert image in Excel by using C# and VB.NET. This guide focuses on how to easily insert image in Excel by using Spire.XLS for .NET.  Developers can use sheet.Pictures.Add(int toprow, int leftcolumn, filename string) method to insert image in Excel directly. Below demonstrates an Excel with an image of flower.

Insert Excel Image

Download and install Spire.XLS for .NET and then use the following code to insert image.

[C#]
using Spire.Xls;

namespace InsertImage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create Workbook
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            //Insert Image
            sheet.Pictures.Add(1, 1, @"E:\work\sample.jpg");

            //Save and Launch
            workbook.SaveToFile("ExcelImage.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("ExcelImage.xlsx");
        }
    }
}
[VB.NET]
Imports Spire.Xls

Namespace InsertImage
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Create Workbook
            Dim workbook As New Workbook()
            Dim sheet As Worksheet = workbook.Worksheets(0)

            'Insert Image
            sheet.Pictures.Add(1, 1, "E:\work\sample.jpg")

            'Save and Launch
            workbook.SaveToFile("ExcelImage.xlsx", ExcelVersion.Version2010)
            System.Diagnostics.Process.Start("ExcelImage.xlsx")
        End Sub
    End Class
End Namespace

Additional Info

  • tutorial_title: Insert Image in Excel
Last modified on Friday, 11 July 2014 08:08