This brief tutorial contains information about how to convert Excel to image in C#. It explains steps to configure the environment of the application, references to the classes required for the conversion of the input XLSX file and to convert Excel to image C# code is presented with description. This tutorial also includes directions to customize the output images as per your requirements like image type is set to JPG.
Steps to Convert Excel to Image using C#
- Configure the project to include Aspose.Cells from Nuget package manager
- Load the source Excel file into the Workbook object for conversion to multiple images
- Get a reference of the target worksheet that is to be transformed into images
- Instantiate a ImageOrPrintOptions class object for output images customization
- Set image type and flag to display all columns per page in the sheet
- Create a SheetRender class object that contains features to create images
- Parse through all the pages and render as an image using the SheetRender object
These steps elaborate how using C# Excel to image conversion can be performed with the help of a simple configuration and a few lines of codes. First load the source Excel file, get a reference to the target sheet that is to be rendered to images, create and use ImageOrPrintOptions object to set properties of the output images, and render each page using the SheetRender object. You can set different properties like image type and flag to display all columns per page of the sheet for better visibility.
Code to Convert Excel to Image in C#
The ImageOrPrintOptions class has comprehensive properties and methods like set grid line type, set the horizontal and vertical resolution of the output images, setting a flag to auto-fit cells based on contents, flag to render complete sheet in a single image, flag to render only a defined area of a sheet, set the quality of the output images, set pixel format, smoothing mode, transparency of the images and many more. To convert Excel to image C# code demonstrates a few properties however you may set any of the properties as per your requirements.
This tutorial has guided us on how to convert Excel to image in C#. If you want to learn to convert Excel to HTML, refer to the article on how to convert Excel to HTML using C#.