إنشاء بيانات شكل معايرة شريطية للصور
Contents
[
Hide
]
في بعض الأحيان، تحتاج إلى إنشاء صور لأشرطة التنسيق الشرطي. يمكنك استخدام طريقة Aspose.Cells DataBar.to_image() لإنشاء هذه الصور. يُظهر هذا المقال كيفية إنشاء صورة لشفرة البيانات باستخدام Aspose.Cells للبايثون via .NET.
يُنشئ الشفرة النموذجية التالية صورة DataBar للخلية C1. أولاً، يصل إلى كائن شرط التنسيق للخلية، ومن ثم من ذلك الكائن، يصل إلى الكائن DataBar ويستخدم طريقة to_image() لإنشاء صورة الخلية. في النهاية، يقوم بحفظ الصورة على القرص.
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 CellArea, FormatConditionType, Workbook | |
from aspose.cells.drawing import ImageType | |
from aspose.cells.rendering import ImageOrPrintOptions | |
# 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 excel file | |
workbook = Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access the cell which contains conditional formatting databar | |
cell = worksheet.cells.get("C1") | |
# Create and get the conditional formatting of the worksheet | |
idx = worksheet.conditional_formattings.add() | |
fcc = worksheet.conditional_formattings[idx] | |
fcc.add_condition(FormatConditionType.DATA_BAR) | |
fcc.add_area(CellArea.create_cell_area("C1", "C4")) | |
# Access the conditional formatting databar | |
dbar = fcc[0].data_bar | |
# Create image or print options | |
opts = ImageOrPrintOptions() | |
opts.image_type = ImageType.PNG | |
# Get the image bytes of the databar | |
imgBytes = dbar.to_image(cell, opts) | |
# Write image bytes on the disk | |
with open(outputDir + "outputGenerateDatabarImage.png", "wb") as f: | |
f.write(imgBytes) |