10using NanoXLSX.Registry;
11using NanoXLSX.Registry.Attributes;
13using NanoXLSX.Utils.Xml;
20 [NanoXlsxPlugIn(PlugInUUID = PlugInUUID.ThemeWriter)]
21 internal class ThemeWriter : IPlugInWriter
28 public Workbook Workbook {
get;
set; }
33 public XmlElement XmlElement {
get;
private set; }
40 internal ThemeWriter()
50 public void Init(IBaseWriter baseWriter)
52 this.Workbook = baseWriter.Workbook;
60 Theme workbookTheme = Workbook.WorkbookTheme;
61 XmlElement = XmlElement.CreateElement(
"theme",
"a");
62 XmlElement.AddNameSpaceAttribute(
"a",
"xmlns",
"http://schemas.openxmlformats.org/drawingml/2006/main");
63 XmlElement.AddAttribute(
"name", XmlUtils.SanitizeXmlValue(workbookTheme.Name));
64 XmlElement themeElements = XmlElement.AddChildElement(
"themeElements",
"a");
65 themeElements.AddChildElement(GetColorSchemeElement(workbookTheme.Colors));
67 WriterPlugInHandler.HandleInlineQueuePlugins(ref themeElements, Workbook, PlugInUUID.ThemeInlineWriter);
75 private static XmlElement GetColorSchemeElement(ColorScheme scheme)
77 XmlElement colorScheme = XmlElement.CreateElementWithAttribute(
"clrScheme",
"name", XmlUtils.SanitizeXmlValue(scheme.Name),
"a");
78 colorScheme.AddChildElement(GetColor(
"dk1", scheme.Dark1,
"a"));
79 colorScheme.AddChildElement(GetColor(
"lt1", scheme.Light1,
"a"));
80 colorScheme.AddChildElement(GetColor(
"dk2", scheme.Dark2,
"a"));
81 colorScheme.AddChildElement(GetColor(
"lt2", scheme.Light2,
"a"));
82 colorScheme.AddChildElement(GetColor(
"accent1", scheme.Accent1,
"a"));
83 colorScheme.AddChildElement(GetColor(
"accent2", scheme.Accent2,
"a"));
84 colorScheme.AddChildElement(GetColor(
"accent3", scheme.Accent3,
"a"));
85 colorScheme.AddChildElement(GetColor(
"accent4", scheme.Accent4,
"a"));
86 colorScheme.AddChildElement(GetColor(
"accent5", scheme.Accent5,
"a"));
87 colorScheme.AddChildElement(GetColor(
"accent6", scheme.Accent6,
"a"));
88 colorScheme.AddChildElement(GetColor(
"hlink", scheme.Hyperlink,
"a"));
89 colorScheme.AddChildElement(GetColor(
"folHlink", scheme.FollowedHyperlink,
"a"));
100 private static XmlElement GetColor(
string name, IColor color,
string prefix)
102 XmlElement colorElement = XmlElement.CreateElement(name, prefix);
103 if (color is SystemColor)
105 SystemColor sysColor = color as SystemColor;
106 XmlElement sysColorElement = colorElement.AddChildElementWithAttribute(
"sysClr",
"val", sysColor.StringValue,
"a");
107 if (!
string.IsNullOrEmpty(sysColor.LastColor))
109 sysColorElement.AddAttribute(
"lastClr", sysColor.LastColor);
112 else if (color is SrgbColor)
114 colorElement.AddChildElementWithAttribute(
"srgbClr",
"val", color.StringValue,
"a");