Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void LoadStyleAndColors(ExcelChart chart)
        {
            if (chart.Part == null)
            {
                return;
            }
            var p = chart.WorkSheet.Workbook._package;

            foreach (var rel in chart.Part.GetRelationships())
            {
                if (rel.RelationshipType == ExcelPackage.schemaChartStyleRelationships)
                {
                    StyleUri  = UriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
                    StylePart = p.Package.GetPart(StyleUri);
                    StyleXml  = new XmlDocument();
                    LoadXmlSafe(StyleXml, StylePart.GetStream());
                }
                else if (rel.RelationshipType == ExcelPackage.schemaChartColorStyleRelationships)
                {
                    ColorsUri  = UriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
                    ColorsPart = p.Package.GetPart(ColorsUri);
                    ColorsXml  = new XmlDocument();
                    LoadXmlSafe(ColorsXml, ColorsPart.GetStream());
                }
            }
        }
Exemplo n.º 3
0
        /// <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);
        }