将 Excel 转换为图像

将 Excel 转换为图像

Aspose.Cells for Python via Java 支持将Excel文件转换为不同的图像格式图像。为此,API 提供了图纸渲染图像或打印选项类。此类表示将呈现为图像的工作表。这图纸渲染类提供了印象() 将工作表转换为图像文件的方法。支持 BMP、PNG、JPEG、TIFF 和 EMF 格式。

以下代码片段演示了将 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")