Style.Custom プロパティの設定時にカスタム数値形式を確認する
Contents
[
Hide
]
考えられる使用シナリオ
に無効なカスタム数値形式を割り当てた場合スタイル.カスタムプロパティの場合、Aspose.Cells は例外をスローしません。ただし、Aspose.Cells が割り当てられたカスタム数値形式が有効かどうかを確認する必要がある場合は、次のように設定してください。Workbook.Settings.CheckCustomNumberFormatプロパティへ真実.
Style.Custom プロパティを設定するときは、カスタム数値形式を確認してください
次のサンプル コードは、無効なカスタム数値形式をスタイル.カスタム財産。すでに設定していますので、Workbook.Settings.CheckCustomNumberFormatプロパティへ真実したがって、API は CellsException をスローします。数値形式が無効です.
サンプルコード
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
// 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"); |