Skip to main content
All docs
V24.2

XlsxExportOptionsEx.AllowCellImages Property

Gets or sets whether to export cell images. Available in data-aware export mode for WPF Data Grid and WinForms Data Grid.

Namespace: DevExpress.XtraPrinting

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

Declaration

[DefaultValue(DefaultBoolean.False)]
public DefaultBoolean AllowCellImages { get; set; }

Property Value

Type Default Description
DefaultBoolean False

true to export cell images; otherwise, false.

Available values:

Name Description Return Value
True

The value is true.

0

False

The value is false.

1

Default

The value is specified by a global option or a higher-level object.

2

Remarks

Set the AllowCellImages property to true to export images displayed in grid cells to .xlsx files as cell pictures.

WPF Specifics

Export Images Displayed in Cells

You can export cell images if the grid control meets the following conditions:

The following code sample exports images from the Image column to Excel cells:

Export Images to Excel Cells

<dxg:GridColumn FieldName="Image">
    <dxg:GridColumn.EditSettings>
        <dxe:ImageEditSettings Stretch="None"/>
    </dxg:GridColumn.EditSettings>
</dxg:GridColumn>
public class Record : BindableBase {
    public ImageSource Image {
        get => GetValue<ImageSource>();
        set => SetValue(value);
    }
    // ...
}
// ...
void Button_Click(object sender, RoutedEventArgs e) {
    XlsxExportOptionsEx options = new XlsxExportOptionsEx();
    options.AllowCellImages = DevExpress.Utils.DefaultBoolean.True;
    view.ExportToXlsx(@"c:\work\grid_export.xlsx", options);
}

Replace Cell Content with Images

If grid cells do not contain image data, you can use the XlsxExportOptionsEx.CustomizeCell event to populate document cells with images based on cell values:

Custom Image Export

void Button_Click(object sender, RoutedEventArgs e) {
    XlsxExportOptionsEx options = new XlsxExportOptionsEx();
    options.AllowCellImages = DevExpress.Utils.DefaultBoolean.True;
    options.CustomizeCell += Options_CustomizeCell;
    view.ExportToXlsx(@"c:\work\grid_export.xlsx", options);
}

void Options_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs e) {
    if (e.ColumnFieldName == nameof(Record.IsRead) && e.AreaType == DevExpress.Export.SheetAreaType.DataArea) {
        XlCellAlignment columnAlignment = new XlCellAlignment() {
            HorizontalAlignment = XlHorizontalAlignment.Center
        };
        e.Formatting.Alignment = columnAlignment;
        if ((bool)e.Value)
            e.Value = ImagesExportHelper.ImageUriToByteArray(new System.Uri("pack://application:,,,/DevExpress.Images.v24.2;component/Images/Actions/Apply_32x32.png"));
        else
            e.Value = ImagesExportHelper.ImageUriToByteArray(new System.Uri("pack://application:,,,/DevExpress.Images.v24.2;component/Images/Actions/Cancel_32x32.png"));
    }
    e.Handled = true;
}

The e.Value property accepts images only as Byte[] objects. Use ImagesExportHelper methods to convert images to the required format.

WinForms Specifics

Export Images Displayed in Cells

The WinForms Data Grid can export images if it meets the following requirements:

Note

Images of SvgImage and SvgBitmap types are exported as raster images that depend on the applied skin and DPI. To process vector images in the XlsxExportOptionsEx.CustomizeCell event, render such images as Image objects.

The following code snippet uses the AllowCellImages property to export grid images as cell pictures:

WinForms - Export Images to Excel Cells

void btnExport_Click(object sender, EventArgs e) {
    DevExpress.XtraPrinting.XlsxExportOptionsEx options = new DevExpress.XtraPrinting.XlsxExportOptionsEx();
    options.AllowCellImages = DevExpress.Utils.DefaultBoolean.True;
    advBandedGridView1.ExportToXlsx("grid_export.xlsx", options);
}

Replace Cell Content with Images

If grid cells do not contain image data, you can use the XlsxExportOptionsEx.CustomizeCell event to populate document cells with images based on cell values. The following code snippet adds placeholder images during the export operation if cells in the Photo column are empty:

WinForms - Customize Export Images to Excel Cells

void Options_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs e) {
    if(e.ColumnFieldName == "Photo" && e.Value == null) {
        e.Value = DevExpress.XtraEditors.Controls.ByteImageConverter.ToByteArray(imageCollection1.Images["car"]);
        e.Handled = true;
    }
}

The e.Value property accepts images only as Byte[] objects. Use ByteImageConverter methods to convert images to the required format.

See Also