use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.
the class DataValidationEvaluator method getValidationContextForCell.
/**
* Finds and returns the {@link DataValidationContext} for the cell, if there is
* one. Lookup is based on the first match from
* {@link DataValidation#getRegions()} for the cell's sheet. DataValidation
* regions must be in the same sheet as the DataValidation. Allowed values
* expressions may reference other sheets, however.
*
* @param cell reference to check
* @return the DataValidationContext applicable to the given cell, or null if no
* validation applies
*/
public DataValidationContext getValidationContextForCell(CellReference cell) {
final Sheet sheet = workbook.getSheet(cell.getSheetName());
if (sheet == null)
return null;
final List<? extends DataValidation> dataValidations = getValidations(sheet);
if (dataValidations == null)
return null;
for (DataValidation dv : dataValidations) {
final CellRangeAddressList regions = dv.getRegions();
if (regions == null)
return null;
// current implementation can't return null
for (CellRangeAddressBase range : regions.getCellRangeAddresses()) {
if (range.isInRange(cell)) {
return new DataValidationContext(dv, this, range, cell);
}
}
}
return null;
}
use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.
the class TestXSSFDataValidation method createValidation.
private XSSFDataValidation createValidation(XSSFSheet sheet) {
//create the cell that will have the validation applied
final Row row = sheet.createRow(0);
row.createCell(0);
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("true");
final XSSFDataValidation validation = (XSSFDataValidation) dataValidationHelper.createValidation(constraint, new CellRangeAddressList(0, 0, 0, 0));
return validation;
}
use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.
the class CFHeaderBase method createEmpty.
protected void createEmpty() {
field_3_enclosing_cell_range = new CellRangeAddress(0, 0, 0, 0);
field_4_cell_ranges = new CellRangeAddressList();
}
use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.
the class CFHeaderBase method read.
protected void read(RecordInputStream in) {
field_1_numcf = in.readShort();
field_2_need_recalculation_and_id = in.readShort();
field_3_enclosing_cell_range = new CellRangeAddress(in);
field_4_cell_ranges = new CellRangeAddressList(in);
}
use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.
the class TestPLVRecord method testPLVRecord.
public void testPLVRecord() throws Exception {
InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME);
HSSFWorkbook workbook = new HSSFWorkbook(is);
CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1);
DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION);
HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint);
// This used to throw an error before
try {
workbook.getSheet(SHEET_NAME).addValidationData(dataValidation);
} catch (IllegalStateException ex) {
throw new AssertionFailedError("Identified bug 53972, PLV record breaks addDataValidation()");
}
}
Aggregations