Skip to main content
All docs
V24.2

How to: Place a Picture in a Cell

  • 2 minutes to read

You can place an image in a cell similar to the “Place in Cell” option in Microsoft Excel. Such image types are available in the XLSX, XLSM, XLTX, and XLTM document formats.

Note

The WPF Spreadsheet control does not display, print or export (to PDF) in-cell images. However, it saves these images to a document, so that you can view and print the document in Microsoft® Excel® or another spreadsheet application.

Use the CellRange.Value property to assign an image to a cell. The following object types are available as an image source:

The Cell.ImageInfo property allows you to specify additional image information: alternative text and whether the image is marked as decorative.

The following code snippet places an image from a stream in a cell and specifies its alternative text:

Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;

MemoryStream imageStream = new MemoryStream(imageBytes);

// Insert cell images from a stream
worksheet.Cells["A2"].Value = imageStream;


// Specify image information
if (worksheet.Cells["A2"].Value.IsCellImage) {
    worksheet.Cells["A2"].ImageInfo.Decorative = true;
    worksheet.Cells["A2"].ImageInfo.AlternativeText = "Image AltText";
}

workbook.SaveDocument("result.xlsx");

To determine if a cell has an embedded image, use the CellValue.IsCellImage property. Use the CellValue.ImageValue property to obtain the cell image value as an OfficeImage object.