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

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

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

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

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Create a workbook
Workbook wb = 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
wb.getSettings().setCheckCustomNumberFormat(true);
// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
// Access cell A1 and put some number inside it
Cell c = ws.getCells().get("A1");
c.putValue(2347);
// Access cell's style and set its Style.Custom property
Style s = c.getStyle();
try {
// This line will throw exception if
// Workbook.Settings.CheckCustomNumberFormat is set to true
s.setCustom("ggg @ fff"); // Invalid custom number format
c.setStyle(s);
}
catch (Exception ex) {
System.out.println("Exception Occured");
}
System.out.println("Done");