Benutzerdefiniertes Zahlenformat überprüfen beim Festlegen von Style.Custom Eigenschaft
Mögliche Verwendungsszenarien
Wenn Sie eine ungültige benutzerdefinierte Zahlenformatierung an die Style.setCustom(string) Methode zuweisen, wirft Aspose.Cells for Node.js via C++ keine Ausnahme. Wenn Sie jedoch möchten, dass Aspose.Cells überprüft, ob die zugewiesene benutzerdefinierte Zahlenformatierung gültig ist oder nicht, setzen Sie bitte die Workbook.getSettings().setCheckCustomNumberFormat(boolean)-Methode auf true.
Benutzerdefiniertes Zahlenformat beim Setzen von Style.setCustom(string) überprüfen
Der folgende Beispielcode weist der Style.setCustom(string) Methode eine ungültige benutzerdefinierte Zahlenformatierung zu. Da wir die Workbook.getSettings().setCheckCustomNumberFormat(boolean)-Methode bereits auf true gesetzt haben, löst es eine Ausnahme aus, z.B. Ungültiges Zahlenformat. Lesen Sie die Kommentare im Code für weitere Hilfe.
Beispielcode
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// Create an instance of Workbook class | |
const book = new AsposeCells.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.getSettings().setCheckCustomNumberFormat(true); | |
// Access first worksheet | |
const sheet = book.getWorksheets().get(0); | |
// Access cell A1 and put some number to it | |
const cell = sheet.getCells().get("A1"); | |
cell.putValue(2347); | |
// Access cell's style and set its Style.Custom property | |
const style = cell.getStyle(); | |
// This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
style.setCustom("ggg @ fff"); //Invalid custom number format |