Check Custom Number Format when Setting Style.Custom Property
Possible Usage Scenarios
If you assign invalid custom number format to Style.Custom property, then Aspose.Cells will not throw any exception. But if you want that Aspose.Cells should check if the assigned custom number format is valid or not, then please set the Workbook.Settings.CheckCustomNumberFormat property to true.
Check Custom Number Format when setting Style.Custom property
The following sample code assigns an invalid custom number format to Style.Custom property. Since, we have already set Workbook.Settings.CheckCustomNumberFormat property to true, therefore it throws exception e.g. Invalid number format. Please read the comments inside the code for more help.
Sample Code
// 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 |