تحقق من تنسيق الرقم المخصص عند ضبط خاصية Style.Custom

سيناريوهات الاستخدام المحتملة

إذا قمت بتعيين تنسيق رقم مخصص غير صالح لخاصية Style.Custom، فلن تقوم Aspose.Cells بإلقاء أي استثناء. ولكن إذا كنت ترغب في أن تقوم Aspose.Cells بالتحقق مما إذا كان التنسيق رقم مخصص المعين صالحًا أم لا، فيرجى ضبط الخاصية Workbook.Settings.CheckCustomNumberFormat إلى صحيح.

فحص تنسيق الرقم المخصص عند ضبط خاصية Style.Custom

الكود العيني التالي يعين تنسيق رقم مخصص غير صالح لخاصية Style.Custom. نظرًا لأننا قمنا بالفعل بضبط الخاصية Workbook.Settings.CheckCustomNumberFormat إلى صحيح، لذلك يلقي استثناء مثل تنسيق رقم غير صالح. يرجى قراءة التعليقات داخل الكود للمزيد من المساعدة.

الكود المثالي

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Create an instance of Workbook class
Workbook book = new 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.CheckCustomNumberFormat = true;
// Access first worksheet
Worksheet sheet = book.Worksheets[0];
// Access cell A1 and put some number to it
Cell cell = sheet.Cells["A1"];
cell.PutValue(2347);
// Access cell's style and set its Style.Custom property
Style style = cell.GetStyle();
// This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true
style.Custom = "ggg @ fff"; //Invalid custom number format