تحويل ورقة عمل إلى صورة إزالة الفراغات حول البيانات
إزالة الفراغات حول البيانات
SheetRender API يحول ورقة عمل إلى ملف صورة مع أي سمات محددة، على سبيل المثال، تنسيق الصورة، الصفحات المقسمة، وما إلى ذلك. تدعم عدة صيغ للصور، بما في ذلك BMP، GIF، JPG، TIFF، و EMF.
عند استخدام ميزة الورقة إلى الصورة، يكون للصورة الناتجة فراغ حولها تلقائياً. يمكنك إزالة ذلك عن طريق تعيين الهوامش العلوية، السفلية، اليسرى واليمنى لتوجيه صفحة ورقة المصدر إلى 0 وتحديد ImageOrPrintOptions بشكل مناسب.
الكود التالي يزيل الفراغات حول البيانات في الصورة الناتجة.
from aspose.cells import LoadDataFilterOptions, LoadFilter, LoadOptions, PrintingPageType, 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() | |
# Open the template file | |
book = Workbook(sourceDir + "Book1.xlsx") | |
# Get the first worksheet | |
sheet = book.worksheets[0] | |
options = LoadOptions() | |
options.load_filter = LoadFilter(LoadDataFilterOptions.ALL) | |
# Specify your print area if you want | |
# Sheet.PageSetup.PrintArea = "A1:H8"; | |
# To remove the white border around the image. | |
sheet.page_setup.left_margin = 0.0 | |
sheet.page_setup.right_margin = 0.0 | |
sheet.page_setup.bottom_margin = 0.0 | |
sheet.page_setup.top_margin = 0.0 | |
# Define ImageOrPrintOptions | |
imgOptions = ImageOrPrintOptions() | |
imgOptions.image_type = ImageType.EMF | |
# Set only one page would be rendered for the image | |
imgOptions.one_page_per_sheet = True | |
imgOptions.printing_page = PrintingPageType.IGNORE_BLANK | |
# Create the SheetRender object based on the sheet with its | |
# ImageOrPrintOptions attributes | |
sr = SheetRender(sheet, imgOptions) | |
# Convert the image | |
sr.to_image(0, outputDir + "outputRemoveWhitespaceAroundData.emf") |