Lassen Sie sich die Validierung auf Cell anwenden
Contents
[
Hide
]
Sie können Aspose.Cells API verwenden, um die Validierung auf eine beliebige Zelle anzuwenden. Aspose.Cells bietet dieCell.getValidation Methode zu diesem Zweck. Wenn es keine Validierung für die Zelle gibt, gibt sie null zurück. Ebenso können Sie die verwendenWorksheet.getValidations().getValidationInCell (int-Zeile, int-Spalte)-Methode zum Erfassen der auf eine Zelle angewendeten Validierung durch Bereitstellen ihrer Zeilen- und Spaltenindizes.
Der folgende Schnappschuss zeigt die Excel-Beispieldatei Microsoft, die im Beispielcode unten verwendet wird. CellC1 hatdezimale Validierung angewendet und kann nur Werte annehmenzwischen 10 und 20.
Eine Zelle mit Validierung
Der folgende Beispielcode ruft die auf C1 angewendete Validierung ab und liest seine verschiedenen Eigenschaften.
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()); |
Hier ist die Konsolenausgabe des Beispielcodes, der mit der im obigen Schnappschuss gezeigten Beispieldatei ausgeführt wird.
Reading Properties of Validation
\--------------------------------
Type: 2
Operator: 0
Formula1: =10
Formula2: =20
Ignore blank: true