تحقق من تنسيق الرقم المخصص عند ضبط خاصية Style.Custom
سيناريوهات الاستخدام المحتملة
إذا قمت بتعيين تنسيق رقم مخصص غير صالح لخاصية Style.custom، فلن تقوم Aspose.Cells بإلقاء أي استثناء. ولكن إذا كنت ترغب في أن تقوم Aspose.Cells بالتحقق مما إذا كان التنسيق رقم مخصص المعين صالحًا أم لا، فيرجى ضبط الخاصية Workbook.settings.check_custom_number_format إلى صحيح.
فحص تنسيق الرقم المخصص عند ضبط خاصية Style.Custom
الكود العيني التالي يعين تنسيق رقم مخصص غير صالح لخاصية Style.custom. نظرًا لأننا قمنا بالفعل بضبط الخاصية Workbook.settings.check_custom_number_format إلى صحيح، لذلك يلقي استثناء مثل تنسيق رقم غير صالح. يرجى قراءة التعليقات داخل الكود للمزيد من المساعدة.
الكود المثالي
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create an instance of Workbook class | |
book = Workbook() | |
# Setting this property to true will make Aspose.Cells to throw exception | |
# when invalid custom number format is assigned to Style.Custom property | |
book.settings.check_custom_number_format = True | |
# Access first worksheet | |
sheet = book.worksheets[0] | |
# Access cell A1 and put some number to it | |
cell = sheet.cells.get("A1") | |
cell.put_value(2347) | |
# Access cell's style and set its Style.Custom property | |
style = cell.get_style() | |
# This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
style.custom = "ggg @ fff" |