Excelを画像に変換

Excelを画像に変換

Aspose.Cells for Python via Javaでは、Excelファイルをさまざまな画像形式に変換する機能をサポートしています。このためにAPIはSheetRenderおよびImageOrPrintOptionsクラスを提供しています。

以下のコードスニペットは、ExcelワークシートをPNG画像に変換する方法を示しています。

source_directory = "Examples/SampleFiles/SourceDirectory/"
output_directory = "Examples/SampleFiles/OutputDirectory/"
workbook = Workbook(source_directory + "Book1.xlsx")
imgOptions = ImageOrPrintOptions()
imgOptions.setImageFormat(ImageFormat.getPng())
sheet = workbook.getWorksheets().get(0)
sr = SheetRender(sheet, imgOptions)
for j in range(0, sr.getPageCount()):
sr.toImage(j, output_directory + "WToImage-out%s" %(j) + ".png")