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

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

إذا قمت بتعيين تنسيق رقم مخصص غير صالح لـ Style.setCustom(string) طريقة، فلن ترمي Aspose.Cells for Node.js via C++ أي استثناء. ولكن إذا أردت أن تتحقق Aspose.Cells مما إذا كان تنسيق الرقم المخصص المعين صحيحًا أم لا، يرجى تعيين طريقة Workbook.getSettings().setCheckCustomNumberFormat(boolean) إلى true.

التحقق من تنسيق الرقم المخصص عند تعيين طريقة Style.setCustom(string)

يعين رمز النموذج التالي تنسيق رقم مخصص غير صالح إلى Style.setCustom(string). بما أننا قمنا بالفعل بتعيين Workbook.getSettings().setCheckCustomNumberFormat(boolean) إلى true، يطلق ذلك استثناء، مثل رقم غير صالح. يرجى قراءة التعليقات داخل الكود لمزيد من المساعدة.

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

const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Create an instance of Workbook class
const book = new AsposeCells.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.getSettings().setCheckCustomNumberFormat(true);
// Access first worksheet
const sheet = book.getWorksheets().get(0);
// Access cell A1 and put some number to it
const cell = sheet.getCells().get("A1");
cell.putValue(2347);
// Access cell's style and set its Style.Custom property
const style = cell.getStyle();
// This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true
style.setCustom("ggg @ fff"); //Invalid custom number format