Obtenga la validación aplicada en un Cell
Contents
[
Hide
]
Puede usar Aspose.Cells API para aplicar la validación a cualquier celda. Aspose.Cells proporciona elCell.getValidation método para este propósito. Si no hay validación en la celda, devuelve nulo. Del mismo modo, puede utilizar elWorksheet.getValidations().getValidationInCell(fila int, columna int) para adquirir la validación aplicada a una celda proporcionando sus índices de fila y columna.
La siguiente instantánea muestra el archivo de Excel de ejemplo Microsoft utilizado en el código de ejemplo a continuación. CellC1 poseevalidación decimal aplicado y sólo puede tomar valoresentre 10 y 20.
Una celda con validación
El código de muestra a continuación obtiene la validación aplicada a C1 y lee sus diversas propiedades.
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()); |
Aquí está la salida de la consola del código de muestra ejecutado con el archivo de muestra que se muestra en la instantánea anterior.
Reading Properties of Validation
\--------------------------------
Type: 2
Operator: 0
Formula1: =10
Formula2: =20
Ignore blank: true