Esporta un foglio di lavoro o un grafico in un immagine con larghezza e altezza desiderate
Contents
[
Hide
]
Puoi usare Aspose.Cells per Python via .NET per esportare il tuo foglio di lavoro o grafico in un’immagine con larghezza e altezza desiderate. Offre il metodo ImageOrPrintOptions.set_desired_size() per impostare la larghezza e l’altezza desiderate dell’immagine esportata. La larghezza e l’altezza sono specificate in pixel.
Il seguente codice esporta il foglio di lavoro in un’immagine delle dimensioni 400x400.
This file contains hidden or 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
from aspose.cells import Workbook | |
from aspose.cells.drawing import ImageType | |
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Create workbook object from source file | |
workbook = Workbook(sourceDir + "sampleWorksheetToImageDesiredSize.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Set image or print options we want one page per sheet. The image format is in png and desired dimensions are 400x400 | |
opts = ImageOrPrintOptions() | |
opts.one_page_per_sheet = True | |
opts.image_type = ImageType.PNG | |
opts.set_desired_size(400, 400, False) | |
# Render sheet into image | |
sr = SheetRender(worksheet, opts) | |
sr.to_image(0, outputDir + "outputWorksheetToImageDesiredSize.png") |