Skip to content

Pictures

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

Pictures

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

Example

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

//Add an 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);

The ExcelImage class

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

Properties Description
ImageBytes                                          The image as a byte-array
Type The type of image, for example jpg, gif or svg
Bounds The bounds and resolution of the image

Methods 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