Render the Worksheet and Workbook to Image using ImageOrPrintOptions


Sometimes, you might require presenting your worksheets as a pictorial representation. You do need to present the worksheet images into your applications or web pages. You might need to insert the images into a Word document, a PDF file, a PowerPoint presentation, or use them in some other scenario. Simply you want a worksheet rendered as an image so that you can use it elsewhere. Aspose.Cells supports converting worksheets in Excel files to images. Also, Aspose.Cells supports setting different options like image format, resolution (both vertical and horizontal), image quality, and other image and print options.

The API provides several valuable classes, for example, SheetRender, ImageOrPrintOptions, WorkbookRender, etc.

The SheetRender class handles the task of rendering images for the worksheet whereas the WorkbookRender does the same for a workbook. Both aforesaid classes have several overloaded versions of the toImage method that can directly convert a worksheet or a workbook to image file(s) specified with your desired attributes or options. You can save the image file to the disk/stream. There are several image formats supported, e.g BMP, PNG, GIFF, JPEG, TIFF, EMF, and so on.

Convert Worksheet to Image

Conversion Options

It is possible to save specific pages to image. The following code converts the first and second worksheets in a workbook to JPG images.

Or you can cycle through the workbook and render each worksheet in it to a separate image:

Convert Workbook to Image:

In order to render the complete workbook to image format, you may either use the above approach or simply use the WorkbookRender class that accepts an instance of Workbook as well as the object of ImageOrPrintOptions.

You can save the whole workbook to a single TIFF image with multiply frames or pages: