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

可能な使用シナリオ

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

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

次のサンプルコードでは、Workbook.Settings.CheckCustomNumberFormatプロパティをtrueに設定しているため、無効なカスタム番号書式をStyle.Customプロパティに割り当てます。そのため、APIはCellsException(無効な番号書式)をスローします。

サンプルコード

// 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");