The Aspose.Cells Image Converter for .NET Plugin is a powerful tool that enables developers to convert Excel content into high-quality image formats such as PNG, JPEG, BMP, and more. This plugin supports various Excel file types including XLS, XLSX, CSV, HTML, ODS, and others.
Introduction
The Aspose.Cells Image Converter for .NET Plugin is designed to transform Excel content into high-quality images suitable for reports, documentation, or web applications. With this plugin, you can convert entire workbooks, individual worksheets, cell ranges, and embedded charts into image formats like PNG or JPEG with pixel-perfect accuracy.
Getting Started with Aspose.Cells Image Converter
Install Aspose.Cells for .NET
To start using the Aspose.Cells Image Converter, first install the library via NuGet:
dotnet add package Aspose.Cells
Load an Excel Workbook
Load your Excel workbook into a Workbook
object to begin working with its contents.
using Aspose.Cells;
public class ExcelLoader
{
public static Workbook Load(string filePath)
{
// Load an existing Excel workbook from a file path
return new Workbook(filePath);
}
}
Render a Worksheet to PNG
Convert the first worksheet of the loaded workbook into a PNG image using the following code snippet:
Worksheet sheet = workbook.Worksheets[0];
ImageOrPrintOptions options = new ImageOrPrintOptions { ImageType = ImageType.Png, OnePagePerSheet = true, Resolution = 200 };
SheetRender renderer = new SheetRender(sheet, options);
for (int i = 0; i < renderer.PageCount; i++)
{
renderer.ToImage(i, $"sheet_page_{i + 1}.png");
}
Render an Entire Workbook
To render the entire workbook into a single image file, use the WorkbookRender
class as shown below:
ImageOrPrintOptions options = new ImageOrPrintOptions { ImageType = ImageType.Jpeg };
WorkbookRender render = new WorkbookRender(workbook, options);
render.ToImage(0, "workbook_render.jpg");
Popular Scenarios
Convert Excel Charts to Images
Convert an embedded chart from a worksheet into a standalone PNG image:
Workbook wb = new Workbook("ChartSheet.xlsx");
Worksheet chartSheet = wb.Worksheets[0];
ImageOrPrintOptions chartOptions = new ImageOrPrintOptions { ImageType = ImageType.Png };
SheetRender chartRender = new SheetRender(chartSheet, chartOptions);
chartRender.ToImage(0, "chart.png");
Convert a Cell Range to an Image
Export a specific cell range from the worksheet into an image:
Workbook wb = new Workbook("Data.xlsx");
Range range = wb.Worksheets[0].Cells.CreateRange("A1:C10");
ImageOrPrintOptions rangeOptions = new ImageOrPrintOptions { ImageType = ImageType.Png };
SheetRender rangeRender = new SheetRender(wb.Worksheets[0], rangeOptions);
rangeRender.ToImage(0, "range_output.png");
Render a Pivot Table as an Image
Convert a pivot table from the worksheet into an image:
Workbook wb = new Workbook("PivotData.xlsx");
ImageOrPrintOptions options = new ImageOrPrintOptions { ImageType = ImageType.Png };
SheetRender pivotRender = new SheetRender(wb.Worksheets[0], options);
pivotRender.ToImage(0, "pivot_table.png");
Conclusion
The Aspose.Cells Image Converter for .NET Plugin offers a comprehensive solution for converting Excel content into high-quality images. With its extensive feature set and ease of use, it is an invaluable tool for developers working with Excel data in various applications.