Export Worksheet or Chart into Image with Desired Width and Height

Contents
[ ]

The following code exports the worksheet into an image with 400x400 size.

from aspose.cells import Workbook
from aspose.cells.drawing import ImageType
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# Create workbook object from source file
workbook = Workbook(sourceDir + "sampleWorksheetToImageDesiredSize.xlsx")
# Access first worksheet
worksheet = workbook.worksheets[0]
# Set image or print options we want one page per sheet. The image format is in png and desired dimensions are 400x400
opts = ImageOrPrintOptions()
opts.one_page_per_sheet = True
opts.image_type = ImageType.PNG
opts.set_desired_size(400, 400, False)
# Render sheet into image
sr = SheetRender(worksheet, opts)
sr.to_image(0, outputDir + "outputWorksheetToImageDesiredSize.png")