Проверьте пользовательский формат чисел при установке Style.Custom свойства
Contents
[
Hide
]
Возможные сценарии использования
Если вы назначаете недопустимый настраиваемый формат чисел для свойства Style.custom, то Aspose.Cells не будет генерировать исключение. Но если вы хотите, чтобы Aspose.Cells проверял, является ли назначенный настраиваемый формат чисел допустимым или нет, то установите свойство Workbook.settings.check_custom_number_format в true.
Проверить настраиваемый формат чисел при установке свойства Style.Custom
В следующем образце кода назначается недопустимый настраиваемый формат чисел для свойства Style.custom. Поскольку мы уже установили свойство Workbook.settings.check_custom_number_format в true, поэтому возникает исключение, например, Недопустимый формат числа. Пожалуйста, прочтите комментарии внутри кода для получения дополнительной помощи.
Образец кода
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |