Skip to main content

IXlPicture.AnchorBehavior Property

Gets or sets the positioning and resizing behavior of a picture which is anchored to two cells in a worksheet.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v24.1.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

XlAnchorType AnchorBehavior { get; set; }

Property Value

Type Description
XlAnchorType

One of the XlAnchorType enumeration values.

Available values:

Name Description
TwoCell

Two Cell Anchoring. The picture moves and/or resizes with the underlying cells as specified by the IXlPicture.AnchorBehavior property.

OneCell

One Cell Anchoring. The picture moves with the anchor cell, but its size remains the same.

Absolute

Absolute Anchoring. The picture does not move or resize with the underlying cells.

Remarks

Use the AnchorBehavior property to specify how a picture should be moved and resized when a two cell anchoring type is used to position the picture in a worksheet. The XlAnchorType.Absolute value specifies that the picture does not move or resize with the underlying rows and columns, instead the picture’s anchors should be moved to maintain the same absolute position and size. The XlAnchorType.OneCell specifies that the picture should move with the cell to which the top-left corner of the picture is anchored, but its size does not change. And lastly, use the XlAnchorType.TwoCell value to move and resize the picture with its underlying cells.

Call the IXlPicture.SetTwoCellAnchor method to anchor a picture to two cells in a worksheet and specify how the picture should behave when columns and rows underneath are resized and moved.

The example below uses the IXlPicture.SetTwoCellAnchor method to anchor a picture to two cells in a worksheet. The anchor for the picture’s top-left corner is located at the intersection of the column “B” and the second row, with no offsets. The anchor for the picture’s bottom-right corner is located at the intersection of the column “G” and the twelfth row, with offsets from both the column and row. The IXlPicture.AnchorBehavior is set to XlAnchorType.TwoCell.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

// 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.SetImage(Image.FromFile(Path.Combine(imagesPath, "image1.jpg")), ImageFormat.Jpeg);
        picture.SetTwoCellAnchor(new XlAnchorPoint(1, 1, 0, 0), new XlAnchorPoint(6, 11, 2, 15), XlAnchorType.TwoCell);
    }
}
See Also