26 private enum StyleEnum
58 private static Style bold;
59 private static Style italic;
60 private static Style boldItalic;
61 private static Style underline;
62 private static Style doubleUnderline;
63 private static Style strike;
64 private static Style dateFormat;
65 private static Style timeFormat;
66 private static Style roundFormat;
67 private static Style borderFrame;
68 private static Style borderFrameHeader;
69 private static Style dottedFill_0_125;
70 private static Style mergeCellStyle;
73 #region staticProperties
76 {
get {
return GetStyle(StyleEnum.bold); } }
79 {
get {
return GetStyle(StyleEnum.boldItalic); } }
82 {
get {
return GetStyle(StyleEnum.borderFrame); } }
85 {
get {
return GetStyle(StyleEnum.borderFrameHeader); } }
88 {
get {
return GetStyle(StyleEnum.dateFormat); } }
91 {
get {
return GetStyle(StyleEnum.timeFormat); } }
94 {
get {
return GetStyle(StyleEnum.doubleUnderline); } }
96#pragma warning disable CA1707
98#pragma warning restore CA1707
99 {
get {
return GetStyle(StyleEnum.dottedFill_0_125); } }
102 {
get {
return GetStyle(StyleEnum.italic); } }
105 {
get {
return GetStyle(StyleEnum.mergeCellStyle); } }
108 {
get {
return GetStyle(StyleEnum.roundFormat); } }
111 {
get {
return GetStyle(StyleEnum.strike); } }
114 {
get {
return GetStyle(StyleEnum.underline); } }
117 #region staticMethods
123 private static Style GetStyle(StyleEnum value)
132 bold.CurrentFont.Bold =
true;
136 case StyleEnum.italic:
139 italic =
new Style();
140 italic.CurrentFont.Italic =
true;
144 case StyleEnum.boldItalic:
145 if (boldItalic ==
null)
147 boldItalic =
new Style();
148 boldItalic.CurrentFont.Italic =
true;
149 boldItalic.CurrentFont.Bold =
true;
153 case StyleEnum.underline:
154 if (underline ==
null)
156 underline =
new Style();
157 underline.CurrentFont.Underline = UnderlineValue.Single;
161 case StyleEnum.doubleUnderline:
162 if (doubleUnderline ==
null)
164 doubleUnderline =
new Style();
165 doubleUnderline.CurrentFont.Underline = UnderlineValue.Double;
169 case StyleEnum.strike:
172 strike =
new Style();
173 strike.CurrentFont.Strike =
true;
177 case StyleEnum.dateFormat:
178 if (dateFormat ==
null)
180 dateFormat =
new Style();
181 dateFormat.CurrentNumberFormat.Number = FormatNumber.Format14;
185 case StyleEnum.timeFormat:
186 if (timeFormat ==
null)
188 timeFormat =
new Style();
189 timeFormat.CurrentNumberFormat.Number = FormatNumber.Format21;
193 case StyleEnum.roundFormat:
194 if (roundFormat ==
null)
196 roundFormat =
new Style();
197 roundFormat.CurrentNumberFormat.Number = FormatNumber.Format1;
201 case StyleEnum.borderFrame:
202 if (borderFrame ==
null)
204 borderFrame =
new Style();
205 borderFrame.CurrentBorder.TopStyle = StyleValue.Thin;
206 borderFrame.CurrentBorder.BottomStyle = StyleValue.Thin;
207 borderFrame.CurrentBorder.LeftStyle = StyleValue.Thin;
208 borderFrame.CurrentBorder.RightStyle = StyleValue.Thin;
212 case StyleEnum.borderFrameHeader:
213 if (borderFrameHeader ==
null)
215 borderFrameHeader =
new Style();
216 borderFrameHeader.CurrentBorder.TopStyle = StyleValue.Thin;
217 borderFrameHeader.CurrentBorder.BottomStyle = StyleValue.Medium;
218 borderFrameHeader.CurrentBorder.LeftStyle = StyleValue.Thin;
219 borderFrameHeader.CurrentBorder.RightStyle = StyleValue.Thin;
220 borderFrameHeader.CurrentFont.Bold =
true;
222 s = borderFrameHeader;
224 case StyleEnum.dottedFill_0_125:
225 if (dottedFill_0_125 ==
null)
227 dottedFill_0_125 =
new Style();
228 dottedFill_0_125.CurrentFill.PatternFill = PatternValue.Gray125;
230 s = dottedFill_0_125;
232 case StyleEnum.mergeCellStyle:
233 if (mergeCellStyle ==
null)
235 mergeCellStyle =
new Style();
236 mergeCellStyle.CurrentCellXf.ForceApplyAlignment =
true;
283 public static Style Font(
string fontName,
float fontSize = 11f,
bool isBold =
false,
bool isItalic =
false)
286 s.CurrentFont.Name = fontName;
287 s.CurrentFont.Size = fontSize;
288 s.CurrentFont.Bold = isBold;
289 s.CurrentFont.Italic = isItalic;
Factory class with the most important predefined styles.
static Style ColorizedText(string rgb)
Gets a style to colorize the text of a cell.
static Style Strike
Gets the strike style.
static Style TimeFormat
Gets the time format style.
static Style DateFormat
Gets the date format style.
static Style RoundFormat
Gets the round format style.
static Style Italic
Gets the italic style.
static Style DoubleUnderline
Gets the double underline style.
static Style Underline
Gets the underline style.
static Style MergeCellStyle
Gets the style used when merging cells.
static Style DottedFill_0_125
Gets the special pattern fill style (for compatibility).
static Style Font(string fontName, float fontSize=11f, bool isBold=false, bool isItalic=false)
Gets a style with a user defined font.
static Style BorderFrame
Gets the border frame style.
static Style ColorizedBackground(string rgb)
Gets a style to colorize the background of a cell.
static Style Bold
Gets the bold style.
static Style BorderFrameHeader
Gets the border style for header cells.
static Style BoldItalic
Gets the bold and italic style.
Class representing a Border entry. The Border entry is used to define frames and cell borders.
Class representing a Fill (background) entry. The Fill entry is used to define background colors and ...
void SetColor(string value, FillType fillType)
Sets the color and the depending on fill type.
Class representing a Font entry. The Font entry is used to define text formatting.
Class representing a Style with sub classes within a style sheet. An instance of this class is only a...
Style CopyStyle()
Method to copy the current object to a new one with casting.
Fill CurrentFill
Gets or sets the current Fill object of the style.
Class providing static methods to parse string values to specific types or to print object as languag...
static string ToUpper(string input)
Transforms a string to upper case with null check and invariant culture.
Class providing general validator methods.
static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills or Fo...