Controlla il formato numerico personalizzato durante l'impostazione di Style.Custom Property

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 il formato numero personalizzato durante l’impostazione della proprietà Style.Custom

Il seguente codice di esempio assegna un formato numerico personalizzato non valido aStile.Personalizzato proprietà. Dal momento che abbiamo già impostatoWorkbook.Settings.CheckCustomNumberFormat proprietà aVERO , quindi API genererà CellsException ad esFormato numerico non valido.

Codice d’esempio

// 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");