WorksheetExtensions.CreateThumbnail(Worksheet, String, ImageFileFormat, Int32, Int32, WorksheetThumbnailOptions) Method
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.v24.2.dll
NuGet Package: DevExpress.Document.Processor
Declaration
public static void CreateThumbnail(
this Worksheet sheet,
string fileName,
ImageFileFormat format,
int width,
int height,
WorksheetThumbnailOptions options
)
Parameters
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. |
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 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);
}
Tip
You can use the CellRangeExtensions.ExportToImage extension method of a CellRange object to save a cell range as an image.