internal IXLDataValidation Add(IXLDataValidation dataValidation, bool skipIntersectionsCheck) { if (dataValidation == null) { throw new ArgumentNullException(nameof(dataValidation)); } XLDataValidation xlDataValidation; if (!(dataValidation is XLDataValidation) || dataValidation.Ranges.Any(r => r.Worksheet != Worksheet)) { xlDataValidation = new XLDataValidation(dataValidation, Worksheet); } else { xlDataValidation = (XLDataValidation)dataValidation; } xlDataValidation.RangeAdded += OnRangeAdded; xlDataValidation.RangeRemoved += OnRangeRemoved; foreach (var range in xlDataValidation.Ranges) { ProcessRangeAdded(range, xlDataValidation, skipIntersectionsCheck); } _dataValidations.Add(xlDataValidation); return(xlDataValidation); }
private void ProcessRangeAdded(IXLRange range, XLDataValidation dataValidation, bool skipIntersectionCheck) { if (!skipIntersectionCheck) { SplitExistingRanges(range.RangeAddress); } var indexEntry = new XLDataValidationIndexEntry(range.RangeAddress, dataValidation); _dataValidationIndex.Add(indexEntry); }
public IXLDataValidation SetDataValidation() { foreach (XLRange range in _ranges) { foreach (IXLDataValidation dv in range.Worksheet.DataValidations) { foreach (IXLRange dvRange in dv.Ranges.Where(dvRange => dvRange.Intersects(range))) { dv.Ranges.Remove(dvRange); foreach (IXLCell c in dvRange.Cells().Where(c => !range.Contains(c.Address.ToString()))) { var r = c.AsRange(); r.Dispose(); dv.Ranges.Add(r); } } } } var dataValidation = new XLDataValidation(this); _ranges.First().Worksheet.DataValidations.Add(dataValidation); return(dataValidation); }
public XLDataValidationIndexEntry(IXLRangeAddress rangeAddress, XLDataValidation dataValidation) { RangeAddress = rangeAddress; DataValidation = dataValidation; }