Skip to content

Instantly share code, notes, and snippets.

Code to Create Image of Spreadsheet using Python. For more details: https://kb.aspose.com/cells/python/how-to-create-image-of-spreadsheet-using-python/
from pickle import TRUE
import jpype
import csv
import asposecells
jpype.startJVM()
from asposecells.api import License, Workbook, ImageOrPrintOptions, ImageType, SheetRender
# Instantiate a license
license = License()
license.setLicense("Aspose.Total.lic")
# Load the input XLSX file
wbToRender = Workbook("NewPivotTable.xlsx")
# Instantiate the ImageOrPrintOptions class object
outputImgOptions = ImageOrPrintOptions()
# Set the autofit flag to true
outputImgOptions.setCellAutoFit(True)
# Set the export image type
outputImgOptions.setImageType(ImageType.JPEG)
# Get first worksheet
sheetToRender = wbToRender.getWorksheets().get(0)
# Create SheetRender object for the selected sheet
sheetRenderToImage = SheetRender(sheetToRender, outputImgOptions)
# Loop through all the pages of the sheet and render as a separate image
for j in range(sheetRenderToImage.getPageCount()):
sheetRenderToImage.toImage(j, "ToImage-out" + str(j) + ".jpg")
print("Images rendered for the entire sheet successfully")
jpype.shutdownJVM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment