Überprüfen Sie das benutzerdefinierte Zahlenformat, wenn Sie die Style.Custom-Eigenschaft festlegen
Contents
[
Hide
]
Mögliche Nutzungsszenarien
Wenn Sie ein ungültiges benutzerdefiniertes Zahlenformat zuweisenStil.Benutzerdefiniert-Eigenschaft, dann löst Aspose.Cells keine Ausnahme aus. Wenn Sie aber möchten, dass die Aspose.Cells prüfen soll, ob das zugewiesene benutzerdefinierte Nummernformat gültig ist oder nicht, dann stellen Sie bitte dieWorkbook.Settings.CheckCustomNumberFormat Eigentum zuwahr.
Aktivieren Sie das benutzerdefinierte Zahlenformat, wenn Sie die Eigenschaft Style.Custom festlegen
Der folgende Beispielcode weist ein ungültiges benutzerdefiniertes Zahlenformat zuStil.Benutzerdefiniert Eigentum. Da haben wir schon eingestelltWorkbook.Settings.CheckCustomNumberFormat Eigentum zuwahr, daher wird eine Ausnahme ausgelöst, z. B. Ungültiges Zahlenformat. Bitte lesen Sie die Kommentare im Code für weitere Hilfe.
Beispielcode
This file contains hidden or 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 |