Add Picture or Icon to Excel in C#.NET
Error processing SSI file

How to Insert Picture to Excel in C#.NET Code


The following section shows how to insert a picture / image / icon in an .xlsx spreadsheet file from C# Application .

How to Insert Picture to Spreadsheet in C# language

Support commonly used image format, such as .Jpeg, .Png, .Bmp, .Tiff, .Gif and .ico

Load or Import a Picture

Read picture from local file.

var picture = worksheet.AddPicture("demo-pic.png", "imageFromFile"); 

Read picture from stream (file stream or momery stream).

var picture2 = worksheet.AddPicture(stream, PictureFormat.Jpeg); 

Set Picture Position

Set image position with absolute point.

picture.SetPosition(100, 100); 

Or insert image to target cell.

picture2.SetPosition(worksheet.Cell("A10")); 

Set Picture Size

Allows to change image size to any width and height. If you want to keep the original image size, just not calling the SetSize() method.

picture.SetSize(200, 50); 

Full code for adding Excel picture in C#

var workbook = new Workbook(); var worksheet = workbook.Worksheets.Add("PictureSheet"); ///Insert image from file var picture = worksheet.AddPicture("demo-pic.png", "imageFromFile"); //Set image position with absolute point picture.SetPosition(100, 100); //Set image size, if not set, the image will be shown as original size picture.SetSize(200, 50); ///Insert image from stream using (Stream stream = File.OpenRead("demo-pic2.jpg")) { var picture2 = worksheet.AddPicture(stream, PictureFormat.Jpeg); //Set image position to cell picture2.SetPosition(worksheet.Cell("A10")); //Set image placement picture2.SetPlacement(PicturePlacement.Move); } workbook.Save("Picture.xlsx"); 
What iDiTect .NET Document component can do

We provide powerful & profession document & image controls: How to convert html to pdf in c# Convert any web page to PDF using a powerful tool: iDiTect.Converter Html to Pdf Converter for .NET Convert HTML to Well-Formatted Microsoft Word Convert HTML to / from Word (DOCX) document in C# and VB.NET with iDiTect.Converter component. C# - Generate and save a PDF file you can use a PDF library, load your PDF form, set the values to each field, flatten your file Read and Extract PDF Text from C# / VB.NET applications how to extract all text from PDF file into TXT file (plain text) using PDF Extractor SDK. C#.NET Word to Image Converter SDK Convert Docx Word file into editable images using C# Able to convert multi-page Word document to separate image files by C# programming code. Programmatically convert MS Word DOCX files to PDF in C# A few lines of C# code are all it takes to convert Word to PDF for your .NET application.

More Programming Tutorials
More Programming FAQs