Skip to main content
All docs
V24.1
Row

WorksheetExtensions.CreateThumbnail(Worksheet, Stream, ImageFileFormat, Int32, Int32) Method

Saves the worksheet as an image in the specified format and allows you to set the image size.

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v24.1.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public static void CreateThumbnail(
    this Worksheet sheet,
    Stream stream,
    ImageFileFormat format,
    int width,
    int height
)

Parameters

Name Type Description
sheet Worksheet

The worksheet to be saved as an image.

stream Stream

A stream used to save the output image.

format ImageFileFormat

The output image format.

width Int32

The output image width in pixels.

height Int32

The output image height in pixels.

Remarks

This method generates a thumbnail from the worksheet area that includes the following elements:

  • Cells from the A1 cell to the bottom-right cell that contains data or formatting (excluding hidden rows and columns)
  • Worksheet row and column headers

If the worksheet area is bigger than the thumbnail, the area is cropped to fit the thumbnail. If the worksheet area is smaller, the remaining space is filled with the default background color.

The code sample below saves a worksheet as an image:

Create a Thumbnail Image of the Worksheet

using System.IO;
using DevExpress.Spreadsheet;
// ...

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

    // Access an active worksheet.
    Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;

    // Save the worksheet as an image.
    if (worksheet != null)
    {
        using (FileStream stream = new FileStream("Worksheet_Thumbnail.png", FileMode.Create))
        {
            worksheet.CreateThumbnail(stream, ImageFileFormat.Png, 1600, 900);
        }
    }
}

Tip

You can use the CellRangeExtensions.ExportToImage extension method of a CellRange object to save a cell range as an image.

See Also