Controlla il formato numero personalizzato quando imposti Style.Custom Property
Possibili Scenari di Utilizzo
Se si assegna un formato numero personalizzato non valido a Style.Custom proprietà, allora Aspose.Cells non genererà alcuna eccezione. Ma se si desidera che Aspose.Cells verifichi se il formato numero personalizzato assegnato è valido o meno, si prega di impostare la proprietà Workbook.Settings.CheckCustomNumberFormat su true.
Controlla il formato numero personalizzato quando si imposta la proprietà Style.Custom
Il seguente codice di esempio assegna un formato numero personalizzato non valido alla proprietà Style.Custom. Poiché abbiamo già impostato la proprietà Workbook.Settings.CheckCustomNumberFormat su true, quindi genera un’eccezione ad esempio Formato numero non valido. Si prega di leggere i commenti all’interno del codice per ulteriori informazioni.
Codice di Esempio
// 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 |