NanoXLSX.Formatting 3.1.0
Loading...
Searching...
No Matches
InlineStyleBuilder.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using NanoXLSX.Colors;
9using NanoXLSX.Styles;
10using NanoXLSX.Themes;
11
12// TODO: Consider changing this namespace in a future major release.
13namespace NanoXLSX.Extensions
14{
18 public class InlineStyleBuilder
19 {
20 private Font style = new Font();
21
27 public InlineStyleBuilder FontName(string fontName)
28 {
29 style.Name = fontName;
30 return this;
31 }
32
38 public InlineStyleBuilder Size(float size)
39 {
40 style.Size = size;
41 return this;
42 }
43
49 public InlineStyleBuilder Bold(bool bold = true)
50 {
51 style.Bold = bold;
52 return this;
53 }
54
60 public InlineStyleBuilder Italic(bool italic = true)
61 {
62 style.Italic = italic;
63 return this;
64 }
65
71 public InlineStyleBuilder Strikethrough(bool strikethrough = true)
72 {
73 style.Strike = strikethrough;
74 return this;
75 }
76
82 public InlineStyleBuilder Underline(Font.UnderlineValue style = Styles.Font.UnderlineValue.Single)
83 {
84 this.style.Underline = style;
85 return this;
86 }
87
94 {
95 style.ColorValue = color;
96 return this;
97 }
98
105 public InlineStyleBuilder ColorArgb(string argb)
106 {
107 style.ColorValue = Colors.Color.CreateRgb(argb);
108 return this;
109 }
110
117 public InlineStyleBuilder ColorTheme(Theme.ColorSchemeElement theme, double tint = 0.0)
118 {
119 style.ColorValue = Colors.Color.CreateTheme(theme, tint);
120 return this;
121 }
122
128 public InlineStyleBuilder ColorIndexed(IndexedColor.Value indexed)
129 {
130 style.ColorValue = Colors.Color.CreateIndexed(indexed);
131 return this;
132 }
133
139 public InlineStyleBuilder ColorIndexed(int colorIndex)
140 {
141 style.ColorValue = Colors.Color.CreateIndexed(colorIndex);
142 return this;
143 }
144
150 public InlineStyleBuilder VerticalAlign(Font.VerticalTextAlignValue alignment)
151 {
152 style.VerticalAlign = alignment;
153 return this;
154 }
155
161 {
162 style.VerticalAlign = Font.VerticalTextAlignValue.Superscript;
163 return this;
164 }
165
171 {
172 style.VerticalAlign = Font.VerticalTextAlignValue.Subscript;
173 return this;
174 }
175
181 public InlineStyleBuilder Outline(bool outline = true)
182 {
183 style.Outline = outline;
184 return this;
185 }
186
192 public InlineStyleBuilder Shadow(bool shadow = true)
193 {
194 style.Shadow = shadow;
195 return this;
196 }
197
203 public InlineStyleBuilder Condense(bool condense = true)
204 {
205 style.Condense = condense;
206 return this;
207 }
208
214 public InlineStyleBuilder Extend(bool extend = true)
215 {
216 style.Extend = extend;
217 return this;
218 }
219
225 public InlineStyleBuilder Charset(Font.CharsetValue charset)
226 {
227 style.Charset = charset;
228 return this;
229 }
230
236 public InlineStyleBuilder Family(Font.FontFamilyValue family)
237 {
238 style.Family = family;
239 return this;
240 }
241
247 public InlineStyleBuilder Scheme(Font.SchemeValue scheme)
248 {
249 style.Scheme = scheme;
250 return this;
251 }
252
258 public Font Build(bool reset = true)
259 {
260 Font instance = style.CopyFont();
261 if (reset)
262 {
263 style = new Font();
264 }
265 return instance;
266 }
267 }
268}
Builder for creating inline Styles.Font styles with a fluent API.
InlineStyleBuilder Extend(bool extend=true)
Sets whether the font is extended.
Font Build(bool reset=true)
Builds the inline style instance.
InlineStyleBuilder Subscript()
Sets the font to subscript.
InlineStyleBuilder ColorIndexed(IndexedColor.Value indexed)
Sets the font color from an indexed color value.
InlineStyleBuilder Color(Color color)
Sets the font color.
InlineStyleBuilder Underline(Font.UnderlineValue style=Styles.Font.UnderlineValue.Single)
Sets the underline style for the font.
InlineStyleBuilder Condense(bool condense=true)
Sets whether the font is condensed.
InlineStyleBuilder ColorIndexed(int colorIndex)
Sets the font color from an indexed color value, using the index number (0-65).
InlineStyleBuilder Italic(bool italic=true)
Sets whether the font is italic.
InlineStyleBuilder Shadow(bool shadow=true)
Sets whether the font has shadow.
InlineStyleBuilder Family(Font.FontFamilyValue family)
Sets the font family.
InlineStyleBuilder Bold(bool bold=true)
Sets whether the font is bold.
InlineStyleBuilder Strikethrough(bool strikethrough=true)
Sets whether the font has strikethrough.
InlineStyleBuilder VerticalAlign(Font.VerticalTextAlignValue alignment)
Sets the vertical alignment for the font.
InlineStyleBuilder FontName(string fontName)
Sets the font name for the inline style.
InlineStyleBuilder Superscript()
Sets the font to superscript.
InlineStyleBuilder Outline(bool outline=true)
Sets whether the font has outline.
InlineStyleBuilder Scheme(Font.SchemeValue scheme)
Sets the font scheme.
InlineStyleBuilder Size(float size)
Sets the font size for the inline style.
InlineStyleBuilder ColorArgb(string argb)
Sets the font color from an RGB or ARGB hex string.
InlineStyleBuilder ColorTheme(Theme.ColorSchemeElement theme, double tint=0.0)
Sets the font color from a theme color.
InlineStyleBuilder Charset(Font.CharsetValue charset)
Sets the font charset.