NanoXLSX.Formatting 3.0.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
12namespace NanoXLSX.Extensions
13{
17 public class InlineStyleBuilder
18 {
19 private Font style = new Font();
20
26 public InlineStyleBuilder FontName(string fontName)
27 {
28 style.Name = fontName;
29 return this;
30 }
31
37 public InlineStyleBuilder Size(float size)
38 {
39 style.Size = size;
40 return this;
41 }
42
48 public InlineStyleBuilder Bold(bool bold = true)
49 {
50 style.Bold = bold;
51 return this;
52 }
53
59 public InlineStyleBuilder Italic(bool italic = true)
60 {
61 style.Italic = italic;
62 return this;
63 }
64
70 public InlineStyleBuilder Strikethrough(bool strikethrough = true)
71 {
72 style.Strike = strikethrough;
73 return this;
74 }
75
81 public InlineStyleBuilder Underline(Font.UnderlineValue style = Styles.Font.UnderlineValue.Single)
82 {
83 this.style.Underline = style;
84 return this;
85 }
86
93 {
94 style.ColorValue = color;
95 return this;
96 }
97
104 public InlineStyleBuilder ColorArgb(string argb)
105 {
106 style.ColorValue = Colors.Color.CreateRgb(argb);
107 return this;
108 }
109
116 public InlineStyleBuilder ColorTheme(Theme.ColorSchemeElement theme, double tint = 0.0)
117 {
118 style.ColorValue = Colors.Color.CreateTheme(theme, tint);
119 return this;
120 }
121
127 public InlineStyleBuilder ColorIndexed(IndexedColor.Value indexed)
128 {
129 style.ColorValue = Colors.Color.CreateIndexed(indexed);
130 return this;
131 }
132
138 public InlineStyleBuilder ColorIndexed(int colorIndex)
139 {
140 style.ColorValue = Colors.Color.CreateIndexed(colorIndex);
141 return this;
142 }
143
149 public InlineStyleBuilder VerticalAlign(Font.VerticalTextAlignValue alignment)
150 {
151 style.VerticalAlign = alignment;
152 return this;
153 }
154
160 {
161 style.VerticalAlign = Font.VerticalTextAlignValue.Superscript;
162 return this;
163 }
164
170 {
171 style.VerticalAlign = Font.VerticalTextAlignValue.Subscript;
172 return this;
173 }
174
180 public InlineStyleBuilder Outline(bool outline = true)
181 {
182 style.Outline = outline;
183 return this;
184 }
185
191 public InlineStyleBuilder Shadow(bool shadow = true)
192 {
193 style.Shadow = shadow;
194 return this;
195 }
196
202 public InlineStyleBuilder Condense(bool condense = true)
203 {
204 style.Condense = condense;
205 return this;
206 }
207
213 public InlineStyleBuilder Extend(bool extend = true)
214 {
215 style.Extend = extend;
216 return this;
217 }
218
224 public InlineStyleBuilder Charset(Font.CharsetValue charset)
225 {
226 style.Charset = charset;
227 return this;
228 }
229
235 public InlineStyleBuilder Family(Font.FontFamilyValue family)
236 {
237 style.Family = family;
238 return this;
239 }
240
246 public InlineStyleBuilder Scheme(Font.SchemeValue scheme)
247 {
248 style.Scheme = scheme;
249 return this;
250 }
251
257 public Font Build(bool reset = true)
258 {
259 Font instance = style.CopyFont();
260 if (reset)
261 {
262 style = new Font();
263 }
264 return instance;
265 }
266 }
267}
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.