All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Replace a Worksheet Picture

  • 2 minutes to read

Use the Picture.ChangeImage method to replace an existing worksheet picture and insert a new picture at the same position. The method’s mode parameter specifies how to resize the new picture. You can set this parameter to one of the following ImageReplacementMode enumeration members:

Stretch (default mode)

This mode is used when you call the Picture.ChangeImage method without the mode parameter. It allows you to maintain the original picture’s size.

Replace a worksheet image - Stretch image

KeepAspectRatio

This mode scales the new picture to fit the largest dimension (width or height) of the original picture. The other dimension is calculated based on the aspect ratio of the inserted image.

Replace a worksheet image - Keep aspect ratio

UseActualSize

Select this mode when you need to keep the new picture’s original dimensions.

Replace a worksheet image - Use actual size

The following example demonstrates how replace an existing picture in a worksheet:

using DevExpress.Spreadsheet;
// ...

IWorkbook workbook = spreadsheetControl.Document;
// Set measurement unit to inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
// Insert a picture from a file.
// The picture's top left corner is in the "B2" cell.
var picture = worksheet.Pictures.AddPicture(@"Images\DevAvLogo.png", worksheet.Cells["B2"]);
// Specify the picture size.
picture.Width = 0.5f;
picture.Height = 1f;
// Replace the picture.
picture.ChangeImage(@"Images\DevExpressLogo.png", ImageReplacementMode.KeepAspectRatio);
See Also