スタイル.Customプロパティを設定する際にカスタム番号書式をチェックする
Contents
[
Hide
]
可能な使用シナリオ
Style.Customプロパティに無効なカスタム番号形式を割り当てた場合、Aspose.Cellsは例外をスローしません。ただし、Aspose.Cellsに割り当てたカスタム番号形式が有効かどうかをチェックする場合は、Workbook.Settings.CheckCustomNumberFormatプロパティをtrueに設定してください。
スタイルのカスタムプロパティを設定する際のカスタム番号形式をチェック
次のサンプルコードは、Style.Customプロパティに無効なカスタム番号形式を割り当てます。すでにWorkbook.Settings.CheckCustomNumberFormatプロパティをtrueに設定しているため、例外(無効な番号形式など)がスローされます。詳細についてはコード内のコメントをお読みください。
サンプルコード
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Create an instance of Workbook class | |
Workbook book = 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 | |
book.Settings.CheckCustomNumberFormat = true; | |
// Access first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Access cell A1 and put some number to it | |
Cell cell = sheet.Cells["A1"]; | |
cell.PutValue(2347); | |
// Access cell's style and set its Style.Custom property | |
Style style = cell.GetStyle(); | |
// This line will throw exception if Workbook.Settings.CheckCustomNumberFormat is set to true | |
style.Custom = "ggg @ fff"; //Invalid custom number format |