Controlla il formato numero personalizzato quando imposti Style.Custom Property

Possibili Scenari di Utilizzo

Se assegni un formato numerico personalizzato non valido al metodo Style.setCustom(string), allora Aspose.Cells for Node.js via C++ non lancerà eccezioni. Ma se vuoi che Aspose.Cells verifichi se il formato numerico personalizzato assegnato è valido o meno, imposta il metodo Workbook.getSettings().setCheckCustomNumberFormat(boolean) su true.

Verifica del formato numerico personalizzato durante l’impostazione del metodo Style.setCustom(string)

Il codice di esempio seguente assegna un formato numerico personalizzato non valido al metodo Style.setCustom(string). Poiché abbiamo già impostato il metodo Workbook.getSettings().setCheckCustomNumberFormat(boolean) su true, genera un’eccezione, ad esempio Numero non valido. Leggi i commenti nel codice per ulteriori dettagli.

Codice di Esempio

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