Skip to content

Pictures

Mats Alm edited this page Nov 3, 2023 · 18 revisions

Pictures

EPPlus supports adding pictures/images from a file, a stream or via an image object.

The AddPicture method

Pictures are added to worksheets via the AddPicture method, which is accessed via the Drawings property on ExcelWorksheet. This method has many overloads and returns an ExcelPicture instance. Via the properties of ExcelPicture you can set properties like size, border, fill and other effects.

The ExcelPicture class also has an Image property that represents the actual image. See the ExcelImage class below.

Example

Adding a picture/image to the workbook will work in a very similar way as adding a Shape

//Add a jpg image and apply some effects (EPPlus 6+ interface).
var pic = worksheet.Drawings.AddPicture("Landscape", new FileInfo("c:\\temp\\LandscapeView.jpg"));
pic.SetPosition(2, 0, 1, 0);
pic.Effect.SetPresetShadow(ePresetExcelShadowType.OuterBottomRight);
pic.Effect.OuterShadow.Distance = 10;
pic.Effect.SetPresetSoftEdges(ePresetExcelSoftEdgesType.SoftEdge5Pt);

Landscape

The ExcelImage class

From EPPlus 6, the ExcelImage class replaces all System.Drawing.Common.Image properties (see list above).

Properties

These properties are all readonly.

Name Data type Description
ImageBytes byte[] The image as a byte-array
Type ePictureType The type of image, for example jpg, gif or svg
Bounds ExcelImageInfo The bounds and resolution of the image

Methods

Name Description
SetImage(string) Sets the image from a file path                       
SetImage(FileInfo) Sets the image from a FileInfo object
SetImage(byte[], ePictureType) Sets the image from a byte array
SetImage(Stream, ePictureType) Sets the image from a stream
SetImage(ExcelImage) Sets the image from another image object
SetImageAsync(string) Sets the image from a file path
SetImageAsync(FileInfo) Sets the image from a FileInfo object
SetImageAsync(Stream, ePictureType) Sets the image from a stream

See also

Sample 5.1 (C#) or Sample 5.1 (VB)

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally