Controlla il formato numero personalizzato quando imposti Style.Custom Property
Possibili Scenari di Utilizzo
Se assegni un formato numerico personalizzato non valido alla proprietà Style.Custom allora Aspose.Cells non genererà alcuna eccezione. Ma se vuoi che Aspose.Cells verifichi se il formato numerico personalizzato assegnato è valido o no, imposta la proprietà Workbook.Settings.CheckCustomNumberFormat su true.
Controlla il Formato Numero Personalizzato durante l’impostazione della Proprietà Stile Personalizzato
Il seguente codice di esempio assegna un formato numerico personalizzato non valido alla proprietà Style.Custom. Poiché abbiamo già impostato la proprietà Workbook.Settings.CheckCustomNumberFormat su true, quindi l’API genererà un’eccezione CellsException ad es. Formato numero non valido.
Codice di 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"); |