Skip to main content
A newer version of this page is available. .

IXlSheet.CreatePicture() Method

Creates a picture to be inserted into the worksheet.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v20.2.Core.dll

NuGet Packages: DevExpress.Printing.Core, DevExpress.WindowsDesktop.Printing.Core

Declaration

IXlPicture CreatePicture()

Returns

Type Description
IXlPicture

An IXlPicture object that is the inserted picture.

Remarks

To add a picture to a worksheet, do the following.

  1. Call the CreatePicture method to create a new IXlPicture object.
  2. Set the IXlPicture.Image property to the Image object that specifies the image to be displayed in the worksheet.
  3. To specify the picture’s position in the worksheet, use one of the following methods depending on the anchoring type you wish to use.

    • Absolute Anchoring

      Use the IXlPicture.SetAbsoluteAnchor method to specify the absolute position of the picture within the worksheet and set the picture’s width and height. The picture will not move or resize with the underlying cells.

    • One Cell Anchoring

      Use the IXlPicture.SetOneCellAnchor method to specify the start position for the picture and set the picture’s width and height. The picture will move with the anchor cell, but its size will remain the same.

    • Two Cell Anchoring

      Use the IXlPicture.SetTwoCellAnchor method to specify the start and end positions for the picture and define its anchoring behavior.

For details, refer to the How to: Insert and Position a Picture in a Worksheet article.

Example

The example below demonstrates how to use the IXlPicture.SetTwoCellAnchor method to anchor a picture to two cells in a worksheet. The starting anchor for a picture is located at the intersection of the second column (“B”) and the second row, with no offsets. The final anchor is located at the intersection of the seventh column (“G”) and the twelfth row, with offsets from both the column and row. The IXlPicture.AnchorBehavior is set to XlAnchorType.TwoCell, so that the picture moves and resizes with its underlying cells.

// Create a worksheet.
using (IXlSheet sheet = document.CreateSheet())
{

    // Insert a picture from a file and anchor it to cells. 
    using (IXlPicture picture = sheet.CreatePicture())
    {
        picture.Image = Image.FromFile(Path.Combine(imagesPath, "image1.jpg"));
        picture.SetTwoCellAnchor(new XlAnchorPoint(1, 1, 0, 0), new XlAnchorPoint(6, 11, 2, 15), XlAnchorType.TwoCell);
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreatePicture() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also