التحقق من تنسيق الرقم المخصص عند ضبط خاصية Style.Custom باستخدام C++
سيناريوهات الاستخدام المحتملة
إذا قمت بتعيين تنسيق رقم مخصص غير صالح لخاصية Style.GetCustom()، فلن ترمي مكتبة Aspose.Cells استثناءً. ولكن إذا كنت تريد أن تتحقق Aspose.Cells مما إذا كان التنسيق المخصص المعين صالحًا أم لا، يرجى ضبط الخاصية Workbook.GetCheckCustomNumberFormat() على true.
فحص تنسيق الرقم المخصص عند ضبط خاصية Style.Custom
يُظهر نموذج الشفرة التالي تعيين تنسيق رقم مخصص غير صالح لخاصية Style.GetCustom(). بما أننا قمنا بالفعل بضبط الخاصية Workbook.GetCheckCustomNumberFormat() على true، فإنه يرمي استثناءً، مثلاً، صيغة رقم غير صالحة. اقرأ التعليقات داخل الشفرة للمساعدة.
الكود المثالي
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Create an instance of Workbook class
Workbook book;
// 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
Worksheet sheet = book.GetWorksheets().Get(0);
// Access cell A1 and put some number to it
Cell cell = sheet.GetCells().Get(u"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.SetCustom(u"ggg @ fff"); // Invalid custom number format
std::cout << "Custom number format set." << std::endl;
Aspose::Cells::Cleanup();
}