Controlla il formato numero personalizzato quando imposti Style.Custom Property

Possibili Scenari di Utilizzo

Se si assegna un formato numero personalizzato non valido a Style.custom proprietà, allora Aspose.Cells non genererà alcuna eccezione. Ma se si desidera che Aspose.Cells verifichi se il formato numero personalizzato assegnato è valido o meno, si prega di impostare la proprietà Workbook.settings.check_custom_number_format su true.

Controlla il formato numero personalizzato quando si imposta la proprietà Style.Custom

Il seguente codice di esempio assegna un formato numero personalizzato non valido alla proprietà Style.custom. Poiché abbiamo già impostato la proprietà Workbook.settings.check_custom_number_format su true, quindi genera un’eccezione ad esempio Formato numero non valido. Si prega di leggere i commenti all’interno del codice per ulteriori informazioni.

Codice di Esempio

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Create an instance of Workbook class
book = 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.settings.check_custom_number_format = True
# Access first worksheet
sheet = book.worksheets[0]
# Access cell A1 and put some number to it
cell = sheet.cells.get("A1")
cell.put_value(2347)
# Access cell's style and set its Style.Custom property
style = cell.get_style()
# This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true
style.custom = "ggg @ fff"