Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 4, 2023 03:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aspose-com-gists/5d33fa768a61d24704a7350432266781 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5d33fa768a61d24704a7350432266781 to your computer and use it in GitHub Desktop.
Excel to Image in Python
# load the Excel workbook
workbook = Workbook("Book1.xlsx")
# create image options
imgOptions = ImageOrPrintOptions()
imgOptions.setSaveFormat(SaveFormat.SVG)
# load the worksheet to be rendered
sheet = workbook.getWorksheets().get(0)
# create sheet render object
sr = SheetRender(sheet, imgOptions)
# convert sheet to PNG image
for j in range(0, sr.getPageCount()):
sr.toImage(j, "WorksheetToImage-out%s" %(j) + ".png")
# load the Excel workbook
workbook = Workbook("Book1.xlsx")
# create image options
imgOptions = ImageOrPrintOptions()
imgOptions.setSaveFormat(SaveFormat.SVG)
# get sheet count
sheetCount = workbook.getWorksheets().getCount()
# loop through the sheets
for i in range(0, sheetCount):
sheet = workbook.getWorksheets().get(i)
# convert each sheet to SVG
sr = SheetRender(sheet, imgOptions)
for j in range(0, sr.getPageCount()):
sr.toImage(j, sheet.getName() + "%s" % j + "_out.svg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment