Back to Devexpress

WorksheetExtensions.CreateThumbnail(Worksheet, Int32, Int32) Method

officefileapi-devexpress-dot-spreadsheet-dot-worksheetextensions-dot-createthumbnail-x28-devexpress-dot-spreadsheet-dot-worksheet-system-dot-int32-system-dot-int32-x29.md

latest4.0 KB
Original Source

WorksheetExtensions.CreateThumbnail(Worksheet, Int32, Int32) Method

Saves the worksheet as an image with the specified 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.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public static OfficeImage CreateThumbnail(
    this Worksheet sheet,
    int width,
    int height
)
vb
<ExtensionAttribute>
Public Shared Function CreateThumbnail(
    sheet As Worksheet,
    width As Integer,
    height As Integer
) As OfficeImage

Parameters

NameTypeDescription
sheetWorksheet

The worksheet to be saved as an image.

| | width | Int32 |

The output image width in pixels.

| | height | Int32 |

The output image height in pixels.

|

Returns

TypeDescription
OfficeImage

The output image.

|

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:

csharp
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)
        worksheet.CreateThumbnail(1600, 900).NativeImage.Save("Worksheet_Thumbnail.png");
}
vb
Imports DevExpress.Spreadsheet
' ...

' Create a new Workbook object.
Using workbook As New Workbook()
    ' Load a workbook from a file.
    workbook.LoadDocument("TopTradingPartners.xlsx", DocumentFormat.Xlsx)

    ' Access an active worksheet.
    Dim worksheet As Worksheet = workbook.Worksheets.ActiveWorksheet

    ' Save the worksheet as an image.
    If worksheet IsNot Nothing Then
        worksheet.CreateThumbnail(1600, 900).NativeImage.Save("Worksheet_Thumbnail.png")
    End If
End Using

Tip

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

See Also

WorksheetExtensions Class

WorksheetExtensions Members

DevExpress.Spreadsheet Namespace