Although Excel is used to save, display and calculate data, sometimes, people may add external contents in Excel files, for example, image.
Generally speaking, if we want to insert an image in Excel file, the image may be related to data information. For example, if an Excel file saves some data information of countries, people may insert country flag image in relevant data row.
In this post, I want to introduce a method about how to insert image in Excel by using C#. I will create a new Excel file and then insert an image from my computer to the current worksheet.
Also, Spire.XLS, component for operating Excel, is used in this example, so I add its dll file as reference in my project.
- Declare a new workbook and add an empty worksheet in this workbook.Then, initialize worksheet.
- Add picture in worksheet by using sheet.Pictures.Add() method. There are three parameter passed in this method, start row, start column and image.
- Save this file with a file name and launch it.
Use the following code.
static void Main(string args)
//Create Workbook and Initialize Worskheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;
//Define Location and Insert Picture
sheet.Pictures.Add(1,1, @”D:\work\My Documents\VIP.bmp”);
//Save and Launch File
Click Here to LEARN MORE about Spire.XLS
Click Here to DOWNLOAD Spire.XLS