
In various scenarios, you may want to convert Excel spreadsheets to high-resolution images, for example, when you need to embed the spreadsheet content within your web or desktop applications. In this article, you will learn how to convert Excel XLSX or XLS to images using C# from within the .NET applications.
C# Excel to Image Converter API
Aspose.Cells for .NET is a C# class library that is designed to create and manipulate MS Excel spreadsheets. In addition to spreadsheet automation and manipulation features, the API also provides a built-in converter to convert Excel worksheets to image formats. You can either download the API’s DLL or install it using NuGet.
PM> Install-Package Aspose.Cells
Excel XLSX to Image C# Conversion
Aspose.Cells for .NET allows you to convert Excel worksheets into various popular image formats. The list includes:
The following are the steps to convert an Excel worksheet to image using Aspose.Cells for .NET.
- Load the Excel file using Workbook class.
- Create an instance of ImageOrPrintOptions class.
- Set image type using ImageOrPrintOptions.ImageType property.
- Use ImageType enumeration to select the format of the output image such as JPEG, PNG, etc.
- Select the worksheet you want to render in the Worksheet object.
- Create an object of SheetRender and pass the Worksheet and ImageOrPrintOptions objects to its constructor.
- Loop through the pages using SheetRender.PageCount property to save each page as image using SheetRender.ToImage(Int32, String) method.
The following code sample shows how to convert an Excel worksheet to an image using C#.
Get a Free License
You can get a free temporary license in order to try the API without evaluation limitations.
Conclusion
In this article, you have learned how to convert MS Excel XLSX or XLS files to images using C#. Furthermore, you can convert the Excel files to JPEG, PNG, BMP, TIFF, EMF, and other popular image formats seamlessly. In order to explore more about the C# Excel API, visit the documentation.