Controlla il formato numerico personalizzato durante l'impostazione di Style.Custom Property
Contents
[
Hide
]
Possibili scenari di utilizzo
Se assegni un formato numerico personalizzato non valido aStile.Personalizzatoproperty, quindi Aspose.Cells non genererà alcuna eccezione. Ma se vuoi che Aspose.Cells controlli se il formato del numero personalizzato assegnato è valido o meno, imposta ilWorkbook.Settings.CheckCustomNumberFormat proprietà aVERO.
Controllare Formato numero personalizzato quando si imposta la proprietà Style.Custom
Il seguente codice di esempio assegna un formato numerico personalizzato non valido aStile.Personalizzato proprietà. Da allora, abbiamo già impostatoWorkbook.Settings.CheckCustomNumberFormat proprietà aVERO, quindi genera un’eccezione, ad esempio Formato numerico non valido. Si prega di leggere i commenti all’interno del codice per ulteriore aiuto.
Codice d’esempio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |