How to Convert Excel to Thumbnail Image in C#
How to Convert Excel to Thumbnail Image in C#
When working with document preview features or content libraries, thumbnail images provide a quick visual reference without loading the entire file. This tutorial demonstrates how to create thumbnail images from Excel files using Aspose.Cells for .NET.
Why Use Thumbnails?
- Create preview cards for document galleries
 - Build visual dashboards of spreadsheet reports
 - Add lightweight visuals to search or file management tools
 
Step-by-Step Guide
Step 1: Install Aspose.Cells
dotnet add package Aspose.CellsStep 2: Load the Workbook
Workbook workbook = new Workbook("FinanceReport.xlsx");
Worksheet sheet = workbook.Worksheets[0];Step 3: Configure Thumbnail Rendering Options
ImageOrPrintOptions options = new ImageOrPrintOptions
{
    ImageType = ImageType.Png,
    HorizontalResolution = 96,
    VerticalResolution = 96,
    OnePagePerSheet = true
};Step 4: Render the First Worksheet to an Image
SheetRender renderer = new SheetRender(sheet, options);
renderer.ToImage(0, "preview_temp.png");Step 5: Resize Image to Thumbnail Dimensions (Optional)
You can use a graphics library (e.g., System.Drawing) to resize the image:
using System.Drawing;
Bitmap original = new Bitmap("preview_temp.png");
Bitmap thumbnail = new Bitmap(original, new Size(160, 120));
thumbnail.Save("thumbnail.png");Step 6: Use the Thumbnail Image
Now you have a lightweight thumbnail suitable for previews.
Complete Example Code
using System;
using System.Drawing;
using Aspose.Cells;
using Aspose.Cells.Rendering;
class Program
{
    static void Main()
    {
        // Load Excel file
        Workbook workbook = new Workbook("FinanceReport.xlsx");
        Worksheet sheet = workbook.Worksheets[0];
        // Configure low-resolution options
        ImageOrPrintOptions options = new ImageOrPrintOptions
        {
            ImageType = ImageType.Png,
            HorizontalResolution = 96,
            VerticalResolution = 96,
            OnePagePerSheet = true
        };
        // Render full sheet as a temporary image
        SheetRender renderer = new SheetRender(sheet, options);
        renderer.ToImage(0, "preview_temp.png");
        // Resize to thumbnail
        using (Bitmap original = new Bitmap("preview_temp.png"))
        {
            Bitmap thumbnail = new Bitmap(original, new Size(160, 120));
            thumbnail.Save("thumbnail.png");
        }
        Console.WriteLine("Thumbnail image created from Excel worksheet.");
    }
}Best Practices
| Recommendation | Purpose | 
|---|---|
Use OnePagePerSheet = true | Prevent multi-page splitting in image | 
| Lower resolution | Optimizes for faster thumbnail generation | 
| Resize image after rendering | More control over scaling and quality |