1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | * ******************************************************************************
|
---|
29 | * Jan Källman Initial Release 2009-10-01
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-27
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Globalization;
|
---|
35 | using System.Text;
|
---|
36 | using System.Xml;
|
---|
37 | using System.Linq;
|
---|
38 | namespace OfficeOpenXml
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// Base collection class for styles.
|
---|
42 | /// </summary>
|
---|
43 | /// <typeparam name="T">The style type</typeparam>
|
---|
44 | public class ExcelStyleCollection<T> : IEnumerable<T>
|
---|
45 | {
|
---|
46 | public ExcelStyleCollection()
|
---|
47 | {
|
---|
48 | _setNextIdManual = false;
|
---|
49 | }
|
---|
50 | bool _setNextIdManual;
|
---|
51 | public ExcelStyleCollection(bool SetNextIdManual)
|
---|
52 | {
|
---|
53 | _setNextIdManual = SetNextIdManual;
|
---|
54 | }
|
---|
55 | public XmlNode TopNode { get; set; }
|
---|
56 | internal List<T> _list = new List<T>();
|
---|
57 | Dictionary<string, int> _dic = new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);
|
---|
58 | internal int NextId=0;
|
---|
59 | #region IEnumerable<T> Members
|
---|
60 |
|
---|
61 | public IEnumerator<T> GetEnumerator()
|
---|
62 | {
|
---|
63 | return _list.GetEnumerator();
|
---|
64 | }
|
---|
65 |
|
---|
66 | #endregion
|
---|
67 | #region IEnumerable Members
|
---|
68 |
|
---|
69 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
---|
70 | {
|
---|
71 | return _list.GetEnumerator();
|
---|
72 | }
|
---|
73 | #endregion
|
---|
74 | public T this[int PositionID]
|
---|
75 | {
|
---|
76 | get
|
---|
77 | {
|
---|
78 | return _list[PositionID];
|
---|
79 | }
|
---|
80 | }
|
---|
81 | public int Count
|
---|
82 | {
|
---|
83 | get
|
---|
84 | {
|
---|
85 | return _list.Count;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | //internal int Add(T item)
|
---|
89 | //{
|
---|
90 | // _list.Add(item);
|
---|
91 | // if (_setNextIdManual) NextId++;
|
---|
92 | // return _list.Count-1;
|
---|
93 | //}
|
---|
94 | internal int Add(string key, T item)
|
---|
95 | {
|
---|
96 | _list.Add(item);
|
---|
97 | if (!_dic.ContainsKey(key.ToLower(CultureInfo.InvariantCulture))) _dic.Add(key.ToLower(CultureInfo.InvariantCulture), _list.Count - 1);
|
---|
98 | if (_setNextIdManual) NextId++;
|
---|
99 | return _list.Count-1;
|
---|
100 | }
|
---|
101 | /// <summary>
|
---|
102 | /// Finds the key
|
---|
103 | /// </summary>
|
---|
104 | /// <param name="key">the key to be found</param>
|
---|
105 | /// <param name="obj">The found object.</param>
|
---|
106 | /// <returns>True if found</returns>
|
---|
107 | internal bool FindByID(string key, ref T obj)
|
---|
108 | {
|
---|
109 | if (_dic.ContainsKey(key))
|
---|
110 | {
|
---|
111 | obj = _list[_dic[key.ToLower(CultureInfo.InvariantCulture)]];
|
---|
112 | return true;
|
---|
113 | }
|
---|
114 | else
|
---|
115 | {
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | /// <summary>
|
---|
120 | /// Find Index
|
---|
121 | /// </summary>
|
---|
122 | /// <param name="key"></param>
|
---|
123 | /// <returns></returns>
|
---|
124 | internal int FindIndexByID(string key)
|
---|
125 | {
|
---|
126 | if (_dic.ContainsKey(key))
|
---|
127 | {
|
---|
128 | return _dic[key];
|
---|
129 | }
|
---|
130 | else
|
---|
131 | {
|
---|
132 | return int.MinValue;
|
---|
133 | }
|
---|
134 | }
|
---|
135 | internal bool ExistsKey(string key)
|
---|
136 | {
|
---|
137 | return _dic.ContainsKey(key);
|
---|
138 | }
|
---|
139 | internal void Sort(Comparison<T> c)
|
---|
140 | {
|
---|
141 | _list.Sort(c);
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|