officefileapi-devexpress-dot-spreadsheet-dot-worksheetextensions-dot-createthumbnail-x28-devexpress-dot-spreadsheet-dot-worksheet-system-dot-int32-system-dot-int32-devexpress-dot-spreadsheet-dot-worksheetthumbnailoptions-x29.md
Save the worksheet as an image. Allows you to specify the image size and thumbnail options.
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
public static OfficeImage CreateThumbnail(
this Worksheet sheet,
int width,
int height,
WorksheetThumbnailOptions options
)
<ExtensionAttribute>
Public Shared Function CreateThumbnail(
sheet As Worksheet,
width As Integer,
height As Integer,
options As WorksheetThumbnailOptions
) As OfficeImage
| Name | Type | Description |
|---|---|---|
| sheet | Worksheet |
The worksheet to be saved as an image.
| | width | Int32 |
The output image width in pixels.
| | height | Int32 |
The output image height in pixels.
| | options | WorksheetThumbnailOptions |
An object that defines thumbnail options.
|
| Type | Description |
|---|---|
| OfficeImage |
The output image.
|
This method generates a thumbnail from the worksheet area that includes the following elements:
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 background color.
You can use the WorksheetThumbnailOptions.ColumnOffset and WorksheetThumbnailOptions.RowOffset properties to specify indexes of the column and the row from which to start the worksheet area.
The code sample below specifies thumbnail options and saves a worksheet as an image:
using DevExpress.Spreadsheet;
using System.Drawing;
// ...
// 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;
// Specify thumbnail options.
var thumbnailOptions = new WorksheetThumbnailOptions
{
Resolution = 192,
Scale = 80,
ColumnOffset = 1,
RowOffset = 1,
BackgroundColor = Color.FromArgb(0xF2, 0xF2, 0xF2)
};
// Save the worksheet as an image.
if (worksheet != null)
worksheet.CreateThumbnail(1600, 900, thumbnailOptions).NativeImage.Save("Worksheet_Thumbnail.png");
}
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...
' 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
' Specify thumbnail options.
Dim thumbnailOptions = New WorksheetThumbnailOptions With {
.Resolution = 192,
.Scale = 80,
.ColumnOffset = 1,
.RowOffset = 1,
.BackgroundColor = Color.FromArgb(&HF2, &HF2, &HF2)
}
' Save the worksheet as an image.
If worksheet IsNot Nothing Then
worksheet.CreateThumbnail(1600, 900, thumbnailOptions).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