Çalışma Sayfasındaki Hücre Aralığını Bir Görüntüye Aktarma
Olası Kullanım Senaryoları
Aspose.Cells for Python via .NET kullanarak çalışma sayfası resmi oluşturabilirsiniz. Ancak, bazen, yalnızca belirli bir hücre aralığını resme aktarmak isteyebilirsiniz. Bu durumda, bunu nasıl yapacağınızı anlatan makale.
Bir Çalışma Sayfasındaki Hücre Aralığını Görüntüye Aktar
Bir aralığın görüntüsünü almak için yazdırma alanını istenen aralığa ayarlayın ve tüm kenar boşluklarını sıfıra ayarlayın. Ayrıca ImageOrPrintOptions.one_page_per_sheet değerini true olarak ayarlayın. Aşağıdaki kod, D8:G16 aralığından bir görüntü alır. Koddaki kullanılan örnek Excel dosyasının ekran görüntüsü aşağıdadır. Kodu herhangi bir Excel dosyasıyla deneyebilirsiniz.
Örnek Excel Dosyası ve Dışa Aktarılan Görüntü Ekran Görüntüsü
Kod çalıştırıldığında yalnızca D8:G16 aralığının bir görüntüsü oluşturulur.
Örnek Kod
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 from source file. | |
workbook = Workbook(sourceDir + "sampleExportRangeOfCellsInWorksheetToImage.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Set the print area with your desired range | |
worksheet.page_setup.print_area = "D8:G16" | |
# Set all margins as 0 | |
worksheet.page_setup.left_margin = 0.0 | |
worksheet.page_setup.right_margin = 0.0 | |
worksheet.page_setup.top_margin = 0.0 | |
worksheet.page_setup.bottom_margin = 0.0 | |
# Set OnePagePerSheet option as true | |
options = ImageOrPrintOptions() | |
options.one_page_per_sheet = True | |
options.image_type = ImageType.JPEG | |
options.horizontal_resolution = 200 | |
options.vertical_resolution = 200 | |
# Take the image of your worksheet | |
sr = SheetRender(worksheet, options) | |
sr.to_image(0, outputDir + "outputExportRangeOfCellsInWorksheetToImage.jpg") |