Aspose.Cells Image Converter for .NET
Aspose.Cells Image Converter for .NET is a lightweight, high-performance API designed specifically to transform Microsoft Excel spreadsheets (XLS, XLSX, XLTM, XLSM) into a variety of image formats—including TIFF, JPEG, PNG, BMP, EMF, and GIF—while preserving layout, formatting, charts, and embedded objects. Leveraging the proven rendering engine of Aspose.Cells, this plugin offers fine-grained control over export options, streaming support for large workbooks, and metered licensing to track usage in production environments.
Installation and Setup
Add the Aspose.Cells Image Converter assembly to your .NET project via NuGet or by referencing the DLL directly. For step-by-step guidance, see Installation .
Before rendering any images, initialize metered licensing as described in Metered Licensing .
Key Features and Functionalities
Worksheet-to-Image Conversion
• Render individual worksheets to standalone images with control over page breaks, scaling, and transparency. • Honors Excel print areas, headers/footers, and margins, ensuring fidelity to Print Preview.
Workbook-to-Multi-Page TIFF
• Export entire multi-sheet workbooks into a single, multi-page TIFF container. • Each sheet is rendered as one TIFF frame for archiving or batch processing.
Comprehensive Image Format Support
• Supports TIFF, JPEG, PNG, BMP, EMF, and GIF. • Control compression (LZW, CCITT), interlacing, transparency, and palettes for different formats.
Dynamic File Naming with Placeholders
• Custom Output Patterns: Generate multiple images with intelligent naming conventions using placeholders. • Sheet Index Control: Customize sheet numbering with prefixes and offset values. • Split Part Indexing: Handle large worksheets split across multiple image files with sequential naming. • Automatic File Organization: Systematically name output files based on sheet and page positions.
Rendering Options and Customization
• Fine-tune DPI, resolution, and color depth. • Configure anti-aliasing, gridline visibility, and background fills. • Apply light/dark mode or custom backgrounds for overlays and watermarks.
Chart and Shape Rendering
• Converts charts, SmartArt, OLE objects, and shapes with high fidelity. • Retains themes, styling, axes, and data labels for accurate chart rendering.
Pagination, Scaling, and Print Settings
• Respects Excel pagination for reports. • Scale to fit width/height or specific page counts. • Headers, footers, and page numbers are preserved.
Streaming and Memory Management
• Supports chunked rendering and stream-based output for very large workbooks. • Minimizes memory footprint and avoids out-of-memory issues.
High-Fidelity Text and Font Embedding
• Preserves fonts, alignment, and text flow with embedded or substituted fonts. • Supports RTL, cursive, and Asian scripts for global compatibility.
Thread Safety and Concurrency
• Multiple instances can run in parallel for high-throughput environments. • Thread-safe design ideal for server-side rendering.
Error Handling and Diagnostics
• Detailed error reporting for unsupported features or corrupted files. • Logs warnings for missing fonts or rendering differences.
Usage Examples
Basic Conversion: Excel to Image
The simplest way to convert an Excel file to an image using a single line of code:
using Aspose.Cells.LowCode;
string src = "CellsJava46030_2.xlsx";
ImageConverter.Process(src, "result\\PluginImage.png");
This converts the first worksheet to a PNG image with default settings.
Advanced Conversion with Custom Options
Configure detailed conversion options for precise control over image output:
using Aspose.Cells.LowCode;
using Aspose.Cells;
using System.IO;
string src = "CellsJava46030_2.xlsx";
// Configure load options
LowCodeLoadOptions lclopts = new LowCodeLoadOptions();
lclopts.InputFile = src;
// Configure image save options
LowCodeImageSaveOptions lcsopts = new LowCodeImageSaveOptions();
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Png;
lcsopts.ImageOptions = imgOpts;
// Set up custom file naming with placeholders
LowCodeSaveOptionsProviderOfPlaceHolders p = new LowCodeSaveOptionsProviderOfPlaceHolders(
"result\\PluginImage${SheetIndexPrefix}${SheetIndex}_${SplitPartIndex}.png");
p.SheetIndexOffset = 1; // Start sheet numbering from 1 instead of 0
p.SheetIndexPrefix = "S"; // Add "S" prefix to sheet numbers
p.SplitPartIndexOffset = 1; // Start split part numbering from 1
// Perform conversion
ImageConverter.Process(lclopts, lcsopts, p);
// Verify output
Console.WriteLine(File.Exists("result\\PluginImageS2_2.png")
? "Expected image file has been generated"
: "Cannot find the expected image file");
Feature Breakdown: Dynamic File Naming
Use placeholder-based naming to automatically organize output images from multi-sheet workbooks:
LowCodeSaveOptionsProviderOfPlaceHolders p = new LowCodeSaveOptionsProviderOfPlaceHolders(
"output\\Report${SheetIndexPrefix}${SheetIndex}_Page${SplitPartIndex}.png");
p.SheetIndexOffset = 1; // Sheets numbered from 1
p.SheetIndexPrefix = "Sheet"; // Output: "ReportSheet1_Page1.png"
p.SplitPartIndexOffset = 1; // Pages numbered from 1
Available Placeholders:
${SheetIndex}
: The worksheet index (0-based by default, customizable with offset)${SheetIndexPrefix}
: Custom prefix for sheet numbers (e.g., “S”, “Sheet”, “Tab”)${SplitPartIndex}
: Page/split index for large worksheets (0-based by default, customizable with offset)
Output Examples:
- With prefix “S” and offset 1:
PluginImageS1_1.png
,PluginImageS2_1.png
,PluginImageS2_2.png
- With prefix “Sheet” and offset 1:
ReportSheet1_Page1.png
,ReportSheet2_Page1.png
- No prefix, zero-based:
Output0_0.png
,Output1_0.png
Use Cases:
- Automated batch processing with organized output
- Multi-sheet reports with sequential naming
- Large worksheets split across multiple image files
- Archival systems requiring structured file naming
- Web galleries with predictable image URLs
Feature Breakdown: Image Format Selection
Specify the desired output format for your images:
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
// PNG format (lossless, supports transparency)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Png;
// JPEG format (compressed, smaller file size)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
// TIFF format (multi-page, archival quality)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Tiff;
// BMP format (uncompressed)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Bmp;
// EMF format (vector, scalable)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Emf;
// GIF format (animation support)
imgOpts.ImageType = Aspose.Cells.Drawing.ImageType.Gif;
Feature Breakdown: Sheet Index Customization
Control how sheets are numbered in output files:
// Zero-based indexing (default)
p.SheetIndexOffset = 0; // Sheets: 0, 1, 2, 3...
// One-based indexing (user-friendly)
p.SheetIndexOffset = 1; // Sheets: 1, 2, 3, 4...
// Custom starting point
p.SheetIndexOffset = 100; // Sheets: 100, 101, 102...
// Add descriptive prefixes
p.SheetIndexPrefix = "Q1_"; // Output: PluginImageQ1_1_1.png
p.SheetIndexPrefix = "Report"; // Output: PluginImageReport1_1.png
Feature Breakdown: Split Part Index Customization
Handle large worksheets that split into multiple pages:
// One-based page numbering
p.SplitPartIndexOffset = 1; // Pages: 1, 2, 3, 4...
// Zero-based page numbering
p.SplitPartIndexOffset = 0; // Pages: 0, 1, 2, 3...
// Custom starting page number
p.SplitPartIndexOffset = 10; // Pages: 10, 11, 12...
Traditional API: Granular Control
For maximum control over rendering options, use the traditional SheetRender API:
using Aspose.Cells;
using Aspose.Cells.Rendering;
// Open a template Excel file
Workbook book = new Workbook("Book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageType = ImageType.Png;
imgOptions.HorizontalResolution = 300;
imgOptions.VerticalResolution = 300;
imgOptions.OnlyArea = false;
// Render the sheet to image(s)
SheetRender sr = new SheetRender(sheet, imgOptions);
int pageCount = sr.PageCount;
for (int idxPage = 0; idxPage < pageCount; idxPage++)
{
sr.ToImage(idxPage, "out_" + (idxPage + 1) + ".png");
}
Tips and Best Practices
Performance Optimization
• Use LowCode API: Leverage ImageConverter.Process()
for simpler, faster conversions.
• Caching: Cache frequently used templates for repeated conversions.
• Streaming Mode: Use streaming for high-DPI conversions of large workbooks.
• Dispose Properly: Dispose of workbook and stream objects promptly to free memory.
File Organization
• Placeholder Naming: Use LowCodeSaveOptionsProviderOfPlaceHolders
for systematic file organization.
• Consistent Prefixes: Apply meaningful prefixes (e.g., “Invoice”, “Report”) for easy identification.
• Offset Management: Use 1-based indexing (SheetIndexOffset = 1
) for user-friendly file names.
Quality Control
• Format Selection: Choose PNG for transparency, JPEG for smaller files, TIFF for archival.
• Resolution Settings: Set appropriate DPI values in ImageOrPrintOptions
for print vs. web use.
• Font Verification: Verify font availability to avoid silent substitutions.
• Output Validation: Always check file existence after conversion using File.Exists()
.
Production Deployment
• Initialize Once: Initialize licensing once at startup to avoid repeated checks. • Define Print Areas: Set print areas and page setup in Excel templates for consistency. • Pooled Instances: Use pooled instances for server-side rendering to reduce overhead. • Error Logging: Implement comprehensive error handling and logging for diagnostics.
Common Issues and Resolutions
Issue | Resolution |
---|---|
File not found | Verify that the input file path is correct and accessible |
Unsupported file format | Ensure the file format is supported by the converter |
Expected image not generated | Check placeholder syntax and verify output directory exists |
Incorrect file names | Verify SheetIndexOffset and SheetIndexPrefix settings |
Missing pages | Check SplitPartIndexOffset and ensure all pages are rendered |
Low image quality | Increase DPI/resolution in ImageOrPrintOptions |
Fonts appear different | Install required fonts on the server or configure font substitution |
Frequently Asked Questions
What is Aspose.Cells Image Converter for .NET? A focused tool to programmatically convert Excel spreadsheets into images within .NET applications.
How does it differ from Aspose.Cells for .NET? Aspose.Cells for .NET is a full-featured API, while the Image Converter plugin is tailored for fast and accurate image conversion with streamlined APIs.
Which file formats are supported? Supports XLS, XLSX, XLSM, XLTX, XLTM, XLSB, CSV, TSV, HTML, ODS, and more.
Can I customize image generation?
Yes, using the ImageOrPrintOptions
class to define output type, resolution, compression, and more.
How do I convert multiple sheets to separate images?
Use LowCodeSaveOptionsProviderOfPlaceHolders
with placeholder patterns to automatically generate unique file names for each sheet.
What do the placeholders mean?
${SheetIndex}
: Current worksheet number${SheetIndexPrefix}
: Custom prefix for sheets (e.g., “S”, “Sheet”)${SplitPartIndex}
: Page number for large worksheets split across multiple images
Can I start sheet numbering from 1 instead of 0?
Yes, set SheetIndexOffset = 1
to use one-based indexing.
API Reference Summary
Key Classes
ImageConverter
: Static class providing simplified conversion methodsLowCodeLoadOptions
: Configuration for loading Excel filesLowCodeImageSaveOptions
: Configuration for image outputImageOrPrintOptions
: Detailed image rendering settingsLowCodeSaveOptionsProviderOfPlaceHolders
: Dynamic file naming with placeholders
Essential Properties
InputFile
: Source Excel file pathImageOptions
: Image-specific rendering optionsImageType
: Output format (PNG, JPEG, TIFF, BMP, EMF, GIF)SheetIndexOffset
: Starting number for sheet indexingSheetIndexPrefix
: Prefix string for sheet numbersSplitPartIndexOffset
: Starting number for page/split indexing
Placeholder Tokens
${SheetIndex}
: Worksheet index (with applied offset)${SheetIndexPrefix}
: Custom sheet prefix${SplitPartIndex}
: Page/split index (with applied offset)