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); }
/// <summary> /// Loads a chart style xml file, and applies the style. /// </summary> /// <param name="fallBackStyle">The build in style to fall back on</param> /// <param name="styleXml">The chart style xml document</param> /// <param name="colorsXml">The chart colord xml document</param> /// <returns>The id of the Style loaded</returns> public int LoadStyleXml(XmlDocument styleXml, eChartStyle fallBackStyle, XmlDocument colorsXml = null) { LoadStyleAndColorsXml(styleXml, fallBackStyle, colorsXml); ApplyStyles(); return(Style.Id); }
/// <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); }
private static ExcelStockChart AddStockChartStyle(ExcelWorksheet ws, eStockChartType type, eChartStyle style, string name, int row, int col, ExcelRange range, Action <ExcelStockChart> SetProperties) { var chart = AddStockChart(ws, type, name, row, col, range, SetProperties); chart.Style = style; return(chart); }