/// <summary> /// Constructor /// </summary> /// <param name="worksheet"></param> internal ExcelDataValidationCollection(ExcelWorksheet worksheet) : base(worksheet.NameSpaceManager, worksheet.WorksheetXml.DocumentElement) { Require.Argument(worksheet).IsNotNull("worksheet"); _worksheet = worksheet; SchemaNodeOrder = worksheet.SchemaNodeOrder; // check existing nodes and load them var dataValidationNodes = worksheet.WorksheetXml.SelectNodes(DataValidationItemsPath, worksheet.NameSpaceManager); if (dataValidationNodes != null && dataValidationNodes.Count > 0) { foreach (XmlNode node in dataValidationNodes) { if (node.Attributes["sqref"] == null) { continue; } var addr = node.Attributes["sqref"].Value; var typeSchema = node.Attributes["type"] != null ? node.Attributes["type"].Value : ""; var type = ExcelDataValidationType.GetBySchemaName(typeSchema); _validations.Add(ExcelDataValidationFactory.Create(type, worksheet, addr, node)); } } if (_validations.Count > 0) { OnValidationCountChanged(); } InternalValidationEnabled = true; }
internal ExcelExLstDataValidationCollection(ExcelWorksheet worksheet, DataValidationFormulaListener formulaListener) : base(worksheet.NameSpaceManager, worksheet.WorksheetXml.DocumentElement) { Require.Argument(worksheet).IsNotNull("worksheet"); _worksheet = worksheet; _formulaListener = formulaListener; //SchemaNodeOrder = worksheet.SchemaNodeOrder; SchemaNodeOrder = new string[] { "xmlns:x14", "uri" }; // check validations in the extLst var extLstValidationNodes = worksheet.WorksheetXml.SelectNodes(ExternalDataValidationItemsPath, worksheet.NameSpaceManager); if (extLstValidationNodes != null && extLstValidationNodes.Count > 0) { foreach (XmlNode node in extLstValidationNodes) { var address = base.GetXmlNodeString(node, "xm:sqref"); var uid = node.Attributes["xr:uid"] != null && !string.IsNullOrEmpty(node.Attributes["xr:uid"].Value) ? node.Attributes["xr:uid"].Value : ExcelDataValidation.NewId(); var typeSchema = node.Attributes["type"] != null ? node.Attributes["type"].Value : ""; var type = ExcelDataValidationType.GetBySchemaName(typeSchema); var val = ExcelDataValidationFactory.Create(type, worksheet, address, node, InternalValidationType.ExtLst, uid); val.Uid = uid; _validations.Add(val); } } if (_validations.Count > 0) { OnValidationCountChanged(); } }
/// <summary> /// Creates an <see cref="ExcelDataValidationCollection"/>. Loads any existing data validations from the <paramref name="worksheet"/>. /// </summary> /// <param name="worksheet">The worksheet of the <see cref="ExcelDataValidationCollection"/>.</param> internal ExcelDataValidationCollection(ExcelWorksheet worksheet) : base(worksheet) { // check existing nodes and load them var dataValidationNodes = worksheet.WorksheetXml.SelectNodes(DataValidationItemsPath, worksheet.NameSpaceManager); if (dataValidationNodes != null && dataValidationNodes.Count > 0) { foreach (XmlNode node in dataValidationNodes) { if (node.Attributes["sqref"] == null) { continue; } var addr = node.Attributes["sqref"].Value; var typeSchema = node.Attributes["type"] != null ? node.Attributes["type"].Value : ""; var type = ExcelDataValidationType.GetBySchemaName(typeSchema); _validations.Add(ExcelDataValidationFactory.Create(type, worksheet, addr, node)); } } if (_validations.Count > 0) { base.OnValidationCountChanged(); } }
/// <summary> /// Constructor /// </summary> /// <param name="worksheet"></param> internal ExcelDataValidationCollection(ExcelWorksheet worksheet) : base(worksheet.NameSpaceManager, worksheet.WorksheetXml.DocumentElement) { Require.Argument(worksheet).IsNotNull("worksheet"); _worksheet = worksheet; _formulaListener = new DataValidationFormulaListener(this, _worksheet); SchemaNodeOrder = worksheet.SchemaNodeOrder; // check existing nodes and load them var dataValidationNodes = worksheet.WorksheetXml.SelectNodes(DataValidationItemsPath, worksheet.NameSpaceManager); if (dataValidationNodes != null && dataValidationNodes.Count > 0) { foreach (XmlNode node in dataValidationNodes) { if (node.Attributes["sqref"] == null) { continue; } var addr = node.Attributes["sqref"].Value; var uid = node.Attributes["xr:uid"] != null && !string.IsNullOrEmpty(node.Attributes["xr:uid"].Value) ? node.Attributes["xr:uid"].Value : ExcelDataValidation.NewId(); var typeSchema = node.Attributes["type"] != null ? node.Attributes["type"].Value : ""; var type = ExcelDataValidationType.GetBySchemaName(typeSchema); var validation = ExcelDataValidationFactory.Create(type, worksheet, addr, node, InternalValidationType.DataValidation, uid); validation.Uid = uid; _validations.Add(validation); } } if (_validations.Count > 0) { OnValidationCountChanged(); } _extLstValidations = new ExcelExLstDataValidationCollection(worksheet, _formulaListener); _extListUsed = !_extLstValidations.IsEmpty; InternalValidationEnabled = true; if (worksheet.WorksheetXml.DocumentElement != null) { var xr = worksheet.WorksheetXml.DocumentElement.GetAttribute("xmlns:xr"); if (string.IsNullOrEmpty(xr)) { worksheet.WorksheetXml.DocumentElement.SetAttribute("xmlns:xr", ExcelPackage.schemaXr); var mc = worksheet.WorksheetXml.DocumentElement.GetAttribute("xmlns:mc"); if (mc != ExcelPackage.schemaMarkupCompatibility) { worksheet.WorksheetXml.DocumentElement.SetAttribute("xmlns:mc", ExcelPackage.schemaMarkupCompatibility); } var ignore = worksheet.WorksheetXml.DocumentElement.GetAttribute("mc:Ignorable"); var nsIgnore = ignore.Split(' '); if (!nsIgnore.Contains("xr")) { worksheet.WorksheetXml.DocumentElement.SetAttribute("Ignorable", ExcelPackage.schemaMarkupCompatibility, string.IsNullOrEmpty(ignore) ? "xr" : ignore + " xr"); } } } }