将Excel转换为图像
Contents
[
Hide
]
将Excel转换为图像
Aspose.Cells for Python via Java支持将Excel文件转换为不同的图像形式。为此,API提供了SheetRender和ImageOrPrintOptions类。该类代表将呈现为图像的工作表。SheetRender类提供了toImage()方法,用于将工作表转换为图像文件。支持BMP、PNG、JPEG、TIFF和EMF格式。
以下代码片段演示将Excel工作表转换为PNG图像。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |