internal void LoadStyleAndColorsXml(XmlDocument styleXml, eChartStyle fallBackStyle, XmlDocument colorsXml) { if (fallBackStyle == eChartStyle.None) { throw new ArgumentException("fallBackStyle", "fallBackStyle can't be None"); } if (_chart.Style != eChartStyle.None && _chart.Style != fallBackStyle) { _chart.Style = fallBackStyle; } if (styleXml == null || styleXml.DocumentElement == null || styleXml.DocumentElement.LocalName != "chartStyle" || styleXml.DocumentElement.ChildNodes.Count != 31) { throw new ArgumentException("xml", "StyleXml is null or not in the correct format"); } if (StylePart == null) { CreateStylePart(_chart.WorkSheet.Workbook._package.Package); } StyleXml = styleXml; StyleXml.Save(StylePart.GetStream(FileMode.CreateNew)); Style = new ExcelChartStyle(NameSpaceManager, StyleXml.DocumentElement, this); if (colorsXml == null) { colorsXml = new XmlDocument(); colorsXml.LoadXml(GetStartColorXml()); } LoadColorXml(colorsXml); _chart.InitChartTheme((int)fallBackStyle); }
internal ExcelChartStyleManager(XmlNamespaceManager nameSpaceManager, ExcelChart chart) : base(nameSpaceManager) { _chart = chart; LoadStyleAndColors(chart); if (StylePart != null) { Style = new ExcelChartStyle(nameSpaceManager, StyleXml.DocumentElement, this); } if (ColorsPart != null) { ColorsManager = new ExcelChartColorsManager(nameSpaceManager, ColorsXml.DocumentElement); } _theme = chart.WorkSheet.Workbook.ThemeManager; }
/// <summary> /// Creates an empty style and color for chart, ready to be customized /// </summary> public void CreateEmptyStyle(eChartStyle fallBackStyle = eChartStyle.Style2) { if (fallBackStyle == eChartStyle.None) { throw new InvalidOperationException("The chart must have a style. Please set the charts Style property to a value different than None or Call LoadStyleXml with the fallBackStyle parameter"); } var p = _chart.WorkSheet.Workbook._package.Package; var id = CreateStylePart(p); StyleXml = new XmlDocument(); StyleXml.LoadXml(GetStartStyleXml(id)); StyleXml.Save(StylePart.GetStream()); Style = new ExcelChartStyle(NameSpaceManager, StyleXml.DocumentElement, this); _chart.InitChartTheme((int)fallBackStyle); CreateColorXml(p); }