Skip to main content
All docs
V24.1

How to: Generate a Thumbnail Image from a Chart Sheet

  • 3 minutes to read

The Spreadsheet Document API allows you to create thumbnails for chart sheets. A thumbnail is a small image that you can insert into a document, presentation, or website to display a preview of chart sheet content.

Call the ChartSheetExtensions.CreateThumbnail extension method for a ChartSheet object to generate a thumbnail image of the specified size from a chart sheet. Pass an ImageFileFormat enumeration member to this method to set the thumbnail image format.

Important

The ChartSheetExtensions class is defined in the DevExpress.Docs.v24.1.dll assembly. Add this assembly to your project to use chart sheet extensions. You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this assembly in production code.

If a chart sheet is bigger than the thumbnail image, the chart sheet is cropped to fit the thumbnail. If the chart sheet is smaller, the remaining space is filled with the default background color.

The code sample below saves a chart sheet as an image.

Generate a Thumbnail from the Chart Sheet

using DevExpress.Spreadsheet;
// ...

// Create a new Workbook object.
using (Workbook workbook = new Workbook())
{
    // Load a workbook from a file.
    workbook.LoadDocument("VariableCosts.xlsx", DocumentFormat.Xlsx);

    // Access an active chart sheet.
    ChartSheet chartSheet = workbook.ChartSheets.ActiveChartSheet;

    // Create a thumbnail.
    if (chartSheet != null)
        chartSheet.CreateThumbnail("Chart_sheet_Thumbnail.png", ImageFileFormat.Png, 920, 670);
}

Customize Thumbnail Settings

Create a SheetThumbnailOptions class instance and pass it to the ChartSheetExtensions.CreateThumbnail method to specify thumbnail options. The following options are available:

SheetThumbnailOptions Property Description
BackgroundColor Specifies the background color for the output image.
Resolution Specifies the image resolution (in DPI).
Scale Specifies how to scale content of a chart sheet before it is saved as an image. The Scale property has no effect if the Stretch property is set to true.
Stretch Specifies whether a chart sheet is stretched to fit the output image size.

The code sample below specifies thumbnail options and generates a thumbnail.

Generate a Thumbnail from the Chart Sheet

using DevExpress.Spreadsheet;
using System.Drawing;
// ...

// Create a new Workbook object.
using (Workbook workbook = new Workbook())
{
    // Load a workbook from a file.
    workbook.LoadDocument("VariableCosts.xlsx", DocumentFormat.Xlsx);

    // Access an active chart sheet.
    ChartSheet chartSheet = workbook.ChartSheets.ActiveChartSheet;

    // Specify thumbnail options.
    var thumbnailOptions = new SheetThumbnailOptions
    {
        Resolution = 192,
        Scale = 40,
        BackgroundColor = Color.FromArgb(0xF2, 0xF2, 0xF2)
    };

    // Generate a thumbnail.
    if (chartSheet != null)
        chartSheet.CreateThumbnail("Chart_sheet_Thumbnail.png", ImageFileFormat.Png, 800, 600, thumbnailOptions);
}