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

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

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

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

يعيّن نموذج التعليمات البرمجية التالي تنسيق رقم مخصص غير صالح لـStyle.Custom خاصية. منذ أن وضعنا بالفعلالمصنف.الإعدادات ملكية لحقيقي ، لذلك فإن API سيرمي 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");