[9580] | 1 | using OfficeOpenXml.Utils;
|
---|
| 2 | using System;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 | using System.Collections.ObjectModel;
|
---|
| 5 | using System.Linq;
|
---|
| 6 | using System.Text;
|
---|
| 7 | using System.Xml;
|
---|
| 8 |
|
---|
| 9 | namespace OfficeOpenXml
|
---|
| 10 | {
|
---|
| 11 | public class ExcelProtectedRangeCollection : XmlHelper, IEnumerable<ExcelProtectedRange>
|
---|
| 12 | {
|
---|
| 13 | internal ExcelProtectedRangeCollection(XmlNamespaceManager nsm, XmlNode topNode, ExcelWorksheet ws)
|
---|
| 14 | : base(nsm, topNode)
|
---|
| 15 | {
|
---|
| 16 | foreach (XmlNode protectedRangeNode in topNode.SelectNodes("d:protectedRanges/d:protectedRange", nsm))
|
---|
| 17 | {
|
---|
| 18 | if (!(protectedRangeNode is XmlElement))
|
---|
| 19 | continue;
|
---|
| 20 | _baseList.Add(new ExcelProtectedRange(protectedRangeNode.Attributes["name"].Value, new ExcelAddress(SqRefUtility.FromSqRefAddress(protectedRangeNode.Attributes["sqref"].Value)), nsm, topNode));
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | private List<ExcelProtectedRange> _baseList = new List<ExcelProtectedRange>();
|
---|
| 25 |
|
---|
| 26 | public ExcelProtectedRange Add(string name, ExcelAddress address)
|
---|
| 27 | {
|
---|
| 28 | if (!ExistNode("d:protectedRanges"))
|
---|
| 29 | CreateNode("d:protectedRanges");
|
---|
| 30 |
|
---|
| 31 | var newNode = CreateNode("d:protectedRanges/d:protectedRange");
|
---|
| 32 | var item = new ExcelProtectedRange(name, address, base.NameSpaceManager, newNode);
|
---|
| 33 | _baseList.Add(item);
|
---|
| 34 | return item;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public void Clear()
|
---|
| 38 | {
|
---|
| 39 | DeleteNode("d:protectedRanges");
|
---|
| 40 | _baseList.Clear();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public bool Contains(ExcelProtectedRange item)
|
---|
| 44 | {
|
---|
| 45 | return _baseList.Contains(item);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public void CopyTo(ExcelProtectedRange[] array, int arrayIndex)
|
---|
| 49 | {
|
---|
| 50 | _baseList.CopyTo(array, arrayIndex);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public int Count
|
---|
| 54 | {
|
---|
| 55 | get { return _baseList.Count; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public bool Remove(ExcelProtectedRange item)
|
---|
| 59 | {
|
---|
| 60 | DeleteAllNode("d:protectedRanges/d:protectedRange[@name='" + item.Name + "' and @sqref='" + item.Address.Address + "']");
|
---|
| 61 | if (_baseList.Count == 0)
|
---|
| 62 | DeleteNode("d:protectedRanges");
|
---|
| 63 | return _baseList.Remove(item);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public int IndexOf(ExcelProtectedRange item)
|
---|
| 67 | {
|
---|
| 68 | return _baseList.IndexOf(item);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public void RemoveAt(int index)
|
---|
| 72 | {
|
---|
| 73 | _baseList.RemoveAt(index);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public ExcelProtectedRange this[int index]
|
---|
| 77 | {
|
---|
| 78 | get
|
---|
| 79 | {
|
---|
| 80 | return _baseList[index];
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | IEnumerator<ExcelProtectedRange> IEnumerable<ExcelProtectedRange>.GetEnumerator()
|
---|
| 85 | {
|
---|
| 86 | return _baseList.GetEnumerator();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
---|
| 90 | {
|
---|
| 91 | return _baseList.GetEnumerator();
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|