スタイル.Customプロパティを設定する際にカスタム番号書式をチェックする

可能な使用シナリオ

Style.customプロパティに無効なカスタム番号形式を割り当てた場合、Aspose.Cellsは例外をスローしません。ただし、Aspose.Cellsに割り当てたカスタム番号形式が有効かどうかをチェックする場合は、Workbook.settings.check_custom_number_formatプロパティをtrueに設定してください。

スタイルのカスタムプロパティを設定する際のカスタム番号形式をチェック

次のサンプルコードは、Style.customプロパティに無効なカスタム番号形式を割り当てます。すでにWorkbook.settings.check_custom_number_formatプロパティをtrueに設定しているため、例外(無効な番号形式など)がスローされます。詳細についてはコード内のコメントをお読みください。

サンプルコード

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"