protected void EnsureRootElementExists() { var node = _worksheet.WorksheetXml.SelectSingleNode(DataValidationPath, _worksheet.NameSpaceManager); if (node == null) { base.CreateNode(DataValidationPath.TrimStart('/')); } }
/// <summary> /// Removes an <see cref="ExcelDataValidation"/> from the collection. /// </summary> /// <param name="item">The item to remove.</param> /// <returns>True if remove succeeds, otherwise false.</returns> /// <exception cref="ArgumentNullException">If <paramref name="item"/> is null</exception> public bool Remove(IExcelDataValidation item) { if (!(item is ExcelDataValidation)) { throw new InvalidCastException("The supplied item must inherit OfficeOpenXml.DataValidation.ExcelDataValidation"); } if (item == null) { throw new ArgumentNullException(nameof(item)); } var dvNode = _worksheet.WorksheetXml.DocumentElement.SelectSingleNode(DataValidationPath.TrimStart('/'), NameSpaceManager); dvNode?.RemoveChild(((ExcelDataValidation)item).TopNode); var retVal = _validations.Remove(item); if (retVal) { this.OnValidationCountChanged(); } return(retVal); }