Ü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.BenutzerdefiniertEigenschaft dann Aspose.Cells wird keine Ausnahme auslösen. Aber wenn Sie möchten, dass die Aspose.Cells prüfen soll, ob das zugewiesene benutzerdefinierte Nummernformat gültig ist oder nicht, dann stellen Sie dies bitte einWorkbook.Settings.CheckCustomNumberFormat Eigentum zuwahr.
Überprüfen 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 die API CellsException zB auslösenUngültiges Zahlenformat.
Beispielcode
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-Java | |
// Create a workbook | |
Workbook wb = 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 | |
wb.getSettings().setCheckCustomNumberFormat(true); | |
// Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access cell A1 and put some number inside it | |
Cell c = ws.getCells().get("A1"); | |
c.putValue(2347); | |
// Access cell's style and set its Style.Custom property | |
Style s = c.getStyle(); | |
try { | |
// This line will throw exception if | |
// Workbook.Settings.CheckCustomNumberFormat is set to true | |
s.setCustom("ggg @ fff"); // Invalid custom number format | |
c.setStyle(s); | |
} | |
catch (Exception ex) { | |
System.out.println("Exception Occured"); | |
} | |
System.out.println("Done"); |