Cell に検証を適用する
Contents
[
Hide
]
Aspose.Cells API を使用して、検証を任意のセルに適用できます。 Aspose.Cells は[Cell.getValidation](https://reference.aspose.com/cells/java/com.aspose.cells/cell#getValidation() この目的のためのメソッド。セルに検証がない場合は、null を返します。同様に、Worksheet.getValidations().getValidationInCell(int 行、int 列) 行と列のインデックスを提供することによって、セルに適用される検証を取得するメソッド。
次のスナップショットは、以下のサンプル コードで使用されるサンプル Microsoft Excel ファイルを示しています。 CellC1もっている小数の検証適用され、値のみを取ることができます10から20の間.
検証のあるセル
以下のサンプル コードは、C1 に適用される検証を取得し、そのさまざまなプロパティを読み取ります。
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetValidationAppliedonCell.class); | |
// Instantiate the workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
// Access its first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Cell C1 has the Decimal Validation applied on it. | |
// It can take only the values Between 10 and 20 | |
Cell cell = worksheet.getCells().get("C1"); | |
// Access the valditation applied on this cell | |
Validation validation = cell.getValidation(); | |
// Read various properties of the validation | |
System.out.println("Reading Properties of Validation"); | |
System.out.println("--------------------------------"); | |
System.out.println("Type: " + validation.getType()); | |
System.out.println("Operator: " + validation.getOperator()); | |
System.out.println("Formula1: " + validation.getFormula1()); | |
System.out.println("Formula2: " + validation.getFormula2()); | |
System.out.println("Ignore blank: " + validation.getIgnoreBlank()); |
上記のスナップショットに示されているサンプル ファイルで実行されたサンプル コードからのコンソール出力を次に示します。
Reading Properties of Validation
\--------------------------------
Type: 2
Operator: 0
Formula1: =10
Formula2: =20
Ignore blank: true