9using System.Collections.Generic;
10using NanoXLSX.Exceptions;
23 private List<CellXf> cellXfs =
new List<CellXf>();
24 private Dictionary<int, NumberFormat> numberFormats =
new Dictionary<int, NumberFormat>();
25 private List<Style> styles =
new List<Style>();
26 private List<Border> borders =
new List<Border>();
27 private List<Fill> fills =
new List<Fill>();
28 private List<Font> fonts =
new List<Font>();
29 private List<string> mruColors =
new List<string>();
40 get {
return styles.Count; }
54 Type t = component.GetType();
55 if (t == typeof(CellXf))
57 cellXfs.Add(component as CellXf);
59 else if (t == typeof(NumberFormat))
61 NumberFormat nf = component as NumberFormat;
62 if (nf.InternalID.HasValue && !numberFormats.ContainsKey(nf.InternalID.Value))
64 numberFormats.Add(nf.InternalID.Value, nf);
67 else if (t == typeof(Style))
69 styles.Add(component as Style);
71 else if (t == typeof(Border))
73 borders.Add(component as Border);
75 else if (t == typeof(Fill))
77 fills.Add(component as Fill);
79 else if (t == typeof(Font))
81 fonts.Add(component as Font);
92 return GetComponent(typeof(Style), index) as Style;
102 public Style
GetStyle(
int index, out
bool isDateStyle, out
bool isTimeStyle)
104 Style style = GetComponent(typeof(Style), index) as Style;
109 isDateStyle = NumberFormat.IsDateFormat(style.CurrentNumberFormat.Number);
110 isTimeStyle = NumberFormat.IsTimeFormat(style.CurrentNumberFormat.Number);
122 return GetComponent(typeof(NumberFormat), index) as NumberFormat;
132 return GetComponent(typeof(Border), index) as Border;
142 return GetComponent(typeof(Fill), index) as Fill;
152 return GetComponent(typeof(Font), index) as Font;
170 return cellXfs.Count;
179 return borders.Count;
207 private AbstractStyle GetComponent(Type type,
int index)
211 if (type == typeof(NumberFormat))
213 NumberFormat numberFormat;
214 if (numberFormats.TryGetValue(index, out numberFormat))
218 throw new StyleException(
"The number format with the numFmtId: " + index +
" was not found");
220 else if (type == typeof(Style))
222 return styles[index];
224 else if (type == typeof(Border))
226 return borders[index];
228 else if (type == typeof(Fill))
248 internal void AddMruColor(
string value)
250 this.mruColors.Add(value);
257 internal List<string> GetMruColors()
259 return this.mruColors;
Class representing a collection of pre-processed styles and their components. This class is internall...
Fill GetFill(int index)
Returns a fill component by its index.
Style GetStyle(int index)
Returns a whole style by its index.
int GetNextCellXFId()
Gets the next internal id of a cell XF component.
int GetNextBorderId()
Gets the next internal id of a border component.
int StyleCount
Gets the number of resolved styles.
Style GetStyle(int index, out bool isDateStyle, out bool isTimeStyle)
Returns a whole style by its index. It also returns information about the type of the style.
Border GetBorder(int index)
Returns a border component by its index.
int GetNextFillId()
Gets the next internal id of a fill component.
Font GetFont(int index)
Returns a font component by its index.
void AddStyleComponent(AbstractStyle component)
Adds a style component and determines the appropriate type of it automatically.
int GetNextStyleId()
Gets the next internal id of a style.
NumberFormat GetNumberFormat(int index)
Returns a number format component by its index.
int GetNextFontId()
Gets the next internal id of a font component.