officefileapi-devexpress-dot-spreadsheet-dot-worksheetextensions-dot-createthumbnail-x28-worksheet-string-imagefileformat-int32-int32-worksheetthumbnailoptions-x29.md
Saves the worksheet as an image in the specified format. 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 void CreateThumbnail(
this Worksheet sheet,
string fileName,
ImageFileFormat format,
int width,
int height,
WorksheetThumbnailOptions options
)
<ExtensionAttribute>
Public Shared Sub CreateThumbnail(
sheet As Worksheet,
fileName As String,
format As ImageFileFormat,
width As Integer,
height As Integer,
options As WorksheetThumbnailOptions
)
| Name | Type | Description |
|---|---|---|
| sheet | Worksheet |
The worksheet to be saved as an image.
| | fileName | String |
The file name (including full path) for 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.
| | options | WorksheetThumbnailOptions |
An object that defines thumbnail options.
|
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("Worksheet_Thumbnail.png", ImageFileFormat.Png, 1600, 900, thumbnailOptions);
}
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("Worksheet_Thumbnail.png", ImageFileFormat.Png, 1600, 900, thumbnailOptions)
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