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()); } } }
private void CreateColorXml(ZipPackage p) { CreateColorPart(p); ColorsXml = new XmlDocument(); ColorsXml.LoadXml(GetStartColorXml()); ColorsXml.Save(ColorsPart.GetStream()); ColorsManager = new ExcelChartColorsManager(NameSpaceManager, ColorsXml.DocumentElement); }
/// <summary> /// Load a color xml documents /// </summary> /// <param name="colorXml">The color xml</param> public void LoadColorXml(XmlDocument colorXml) { if (colorXml == null || colorXml.DocumentElement == null || colorXml.DocumentElement.LocalName != "colorStyle" || colorXml.DocumentElement.ChildNodes.Count == 0) { throw new ArgumentException("xml", "ColorXml is null or not in the correct format"); } if (ColorsPart == null) { CreateColorPart(_chart.WorkSheet.Workbook._package.Package); } ColorsXml = colorXml; var stream = ColorsPart.GetStream(FileMode.CreateNew); ColorsXml.Save(stream); ColorsManager = new ExcelChartColorsManager(NameSpaceManager, ColorsXml.DocumentElement); }