所定の幅と高さでワークシートまたはグラフをイメージにエクスポート
Contents
[
Hide
]
Aspose.Cells for Python via .NETを利用して、目的の幅と高さの画像にワークシートやチャートをエクスポートできます。これにはImageOrPrintOptions.set_desired_size()メソッドを使ってエクスポートする画像の幅と高さを設定します。幅と高さはピクセル単位で指定されます。
次のコードは、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") |