Exemplo n.º 1
0
        public Chart()
        {
            Xml      = XDocument.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n                   <c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">  \r\n                       <c:roundedCorners val=\"0\"/>\r\n                       <c:chart>\r\n                           <c:autoTitleDeleted val=\"0\"/>\r\n                           <c:plotVisOnly val=\"1\"/>\r\n                           <c:dispBlanksAs val=\"gap\"/>\r\n                           <c:showDLblsOverMax val=\"0\"/>\r\n                       </c:chart>\r\n                   </c:chartSpace>");
            ChartXml = CreateChartXml();
            XElement xElement = new XElement(XName.Get("plotArea", DocX.c.NamespaceName), new XElement(XName.Get("layout", DocX.c.NamespaceName)), ChartXml);
            XElement content  = XElement.Parse("<c:dLbls xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\">\r\n                    <c:showLegendKey val=\"0\"/>\r\n                    <c:showVal val=\"0\"/>\r\n                    <c:showCatName val=\"0\"/>\r\n                    <c:showSerName val=\"0\"/>\r\n                    <c:showPercent val=\"0\"/>\r\n                    <c:showBubbleSize val=\"0\"/>\r\n                    <c:showLeaderLines val=\"1\"/>\r\n                </c:dLbls>");

            ChartXml.Add(content);
            if (IsAxisExist)
            {
                CategoryAxis = new CategoryAxis("148921728");
                ValueAxis    = new ValueAxis("154227840");
                XElement content2  = XElement.Parse($"<c:axId val=\"{CategoryAxis.Id}\" xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"/>");
                XElement content3  = XElement.Parse($"<c:axId val=\"{ValueAxis.Id}\" xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"/>");
                XElement xElement2 = ChartXml.Element(XName.Get("gapWidth", DocX.c.NamespaceName));
                if (xElement2 != null)
                {
                    xElement2.AddAfterSelf(content3);
                    xElement2.AddAfterSelf(content2);
                }
                else
                {
                    ChartXml.Add(content2);
                    ChartXml.Add(content3);
                }
                xElement.Add(CategoryAxis.Xml);
                xElement.Add(ValueAxis.Xml);
            }
            ChartRootXml = Xml.Root.Element(XName.Get("chart", DocX.c.NamespaceName));
            ChartRootXml.Element(XName.Get("autoTitleDeleted", DocX.c.NamespaceName)).AddAfterSelf(xElement);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create or return an element with the specified Prefix, LocalName and NamespaceUri, and adds it to the document in the specified node.
        /// </summary>
        /// <param name="root">The root node of new element.</param>
        /// <param name="prefix">The prefix of the new element.</param>
        /// <param name="localName">The local name of the new element.</param>
        /// <param name="namespaceUri">The namespace URI of the new element.</param>
        /// <returns>
        /// The new <see cref="System.Xml.XmlNode" />.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> length is less than 1.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> length is less than 1.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> length is less than 1.</exception>
        public static XmlNode CreateOrDefaultAndAppendElementToNode(XmlNode root, string prefix, string localName, string namespaceUri)
        {
            SentinelHelper.ArgumentNull(root);

            SentinelHelper.IsTrue(string.IsNullOrEmpty(prefix), "No puede estar vacio");
            SentinelHelper.IsTrue(prefix.Length < 1, "La longitud minima ha de ser 1");

            SentinelHelper.IsTrue(string.IsNullOrEmpty(localName), "No puede estar vacio");
            SentinelHelper.IsTrue(localName.Length < 1, "La longitud minima ha de ser 1");

            SentinelHelper.IsTrue(string.IsNullOrEmpty(namespaceUri), "No puede estar vacio");
            SentinelHelper.IsTrue(namespaceUri.Length < 1, "La longitud minima ha de ser 1");

            var element = new StringBuilder();

            element.Append(prefix);
            element.Append(":");
            element.Append(localName);

            var exist    = HasElement(root, element.ToString());
            var tempNode = exist ?
                           GetXmlNode(root, element.ToString()) :
                           CreateElement(prefix, localName, namespaceUri);

            if (root == null)
            {
                ChartXml.AppendChild(tempNode);
            }
            else
            {
                root.AppendChild(tempNode);
            }

            return(tempNode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an Chart for this document
        /// </summary>
        public Chart()
        {
            // Create global xml
            Xml = XDocument.Parse
                      (@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>
                   <c:chartSpace xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart"" xmlns:a=""http://schemas.openxmlformats.org/drawingml/2006/main"" xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"">  
                       <c:roundedCorners val=""0""/>
                       <c:chart>
                           <c:autoTitleDeleted val=""0""/>
                           <c:plotVisOnly val=""1""/>
                           <c:dispBlanksAs val=""gap""/>
                           <c:showDLblsOverMax val=""0""/>
                       </c:chart>
                   </c:chartSpace>");

            // Create a real chart xml in an inheritor
            ChartXml = CreateChartXml();

            // Create result plotarea element
            XElement plotAreaXml = new XElement(
                XName.Get("plotArea", DocX.c.NamespaceName),
                new XElement(XName.Get("layout", DocX.c.NamespaceName)),
                ChartXml);

            // Set labels
            XElement dLblsXml = XElement.Parse(
                @"<c:dLbls xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart"">
                    <c:showLegendKey val=""0""/>
                    <c:showVal val=""0""/>
                    <c:showCatName val=""0""/>
                    <c:showSerName val=""0""/>
                    <c:showPercent val=""0""/>
                    <c:showBubbleSize val=""0""/>
                    <c:showLeaderLines val=""1""/>
                </c:dLbls>");

            ChartXml.Add(dLblsXml);

            // if axes exists, create their
            if (IsAxisExist)
            {
                CategoryAxis = new CategoryAxis("148921728");
                ValueAxis    = new ValueAxis("154227840");

                XElement axIDcatXml = XElement.Parse(String.Format(
                                                         @"<c:axId val=""{0}"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart""/>", CategoryAxis.Id));
                XElement axIDvalXml = XElement.Parse(String.Format(
                                                         @"<c:axId val=""{0}"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart""/>", ValueAxis.Id));

                ChartXml.Add(axIDcatXml);
                ChartXml.Add(axIDvalXml);

                plotAreaXml.Add(CategoryAxis.Xml);
                plotAreaXml.Add(ValueAxis.Xml);
            }

            ChartRootXml = Xml.Root.Element(XName.Get("chart", DocX.c.NamespaceName));
            ChartRootXml.Add(plotAreaXml);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add a new series to this chart
 /// </summary>
 public void AddSeries(Series series)
 {
     if (ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count() == MaxSeriesCount)
     {
         throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!");
     }
     ChartXml.Add(series.Xml);
 }
Exemplo n.º 5
0
 internal ExcelStockChart(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) :
     base(drawings, node, type, topChart, PivotTableSource, chartXml, parent)
 {
     if (type == eChartType.StockVHLC || type == eChartType.StockVOHLC)
     {
         var barChart = new ExcelBarChart(this, _chartNode.PreviousSibling, parent);
         barChart.Direction = eDirection.Column;
         _plotArea          = new ExcelChartPlotArea(NameSpaceManager, ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:plotArea", NameSpaceManager), barChart, "c", this);
     }
 }
Exemplo n.º 6
0
 internal ExcelStockChart(ExcelDrawings drawings, XmlNode node, Uri uriChart, ZipPackagePart part, XmlDocument chartXml, XmlNode chartNode, ExcelGroupShape parent = null) :
     base(drawings, node, uriChart, part, chartXml, chartNode, parent)
 {
     if (chartNode.LocalName == "barChart")
     {
         var barChart = new ExcelBarChart(this, chartNode, parent);
         barChart.Direction = eDirection.Column;
         _plotArea          = new ExcelChartPlotArea(NameSpaceManager, ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:plotArea", NameSpaceManager), barChart, "c", this);
         _chartNode         = chartNode.NextSibling;
     }
 }
Exemplo n.º 7
0
        public void AddSeries(Series series)
        {
            int num = ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count();

            if (num == MaxSeriesCount)
            {
                throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!");
            }
            series.Xml.AddFirst(new XElement(XName.Get("order", DocX.c.NamespaceName), new XAttribute(XName.Get("val"), (num + 1).ToString())));
            series.Xml.AddFirst(new XElement(XName.Get("idx", DocX.c.NamespaceName), new XAttribute(XName.Get("val"), (num + 1).ToString())));
            ChartXml.Add(series.Xml);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates an element with the specified Prefix, LocalName, and NamespaceURI.
        /// </summary>
        /// <param name="prefix">The prefix of the new element.</param>
        /// <param name="localName">The local name of the new element.</param>
        /// <param name="namespaceUri">The namespace URI of the new element.</param>
        /// <returns>
        /// The new <see cref="System.Xml.XmlElement" />.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> length is less than 1.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> length is less than 1.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> is empty.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> length is less than 1.</exception>
        public static XmlElement CreateElement(string prefix, string localName, string namespaceUri)
        {
            SentinelHelper.IsTrue(string.IsNullOrEmpty(prefix), "No puede estar vacio");
            SentinelHelper.IsTrue(prefix.Length < 1, "La longitud minima ha de ser 1");

            SentinelHelper.IsTrue(string.IsNullOrEmpty(localName), "No puede estar vacio");
            SentinelHelper.IsTrue(localName.Length < 1, "La longitud minima ha de ser 1");

            SentinelHelper.IsTrue(string.IsNullOrEmpty(namespaceUri), "No puede estar vacio");
            SentinelHelper.IsTrue(namespaceUri.Length < 1, "La longitud minima ha de ser 1");

            return(ChartXml.CreateElement(prefix, localName, namespaceUri));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Add a secondary axis
        /// </summary>
        internal override void AddAxis()
        {
            XmlElement catAx = ChartXml.CreateElement(string.Format("c:{0}", AddAxType()), ExcelPackage.schemaChart);
            int        axID;

            if (_axis.Length == 0)
            {
                _plotArea.TopNode.AppendChild(catAx);
                axID = 1;
            }
            else
            {
                _axis[0].TopNode.ParentNode.InsertAfter(catAx, _axis[_axis.Length - 1].TopNode);
                axID = int.Parse(_axis[0].Id) < int.Parse(_axis[1].Id) ? int.Parse(_axis[1].Id) + 1 : int.Parse(_axis[0].Id) + 1;
            }


            XmlElement valAx = ChartXml.CreateElement("c:valAx", ExcelPackage.schemaChart);

            catAx.ParentNode.InsertAfter(valAx, catAx);

            if (_axis.Length == 0)
            {
                catAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"b\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"autoZero\"/><c:auto val=\"1\"/><c:lblAlgn val=\"ctr\"/><c:lblOffset val=\"100\"/>", axID, axID + 1);
                valAx.InnerXml = string.Format("<c:axId val=\"{1}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"l\"/><c:majorGridlines/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{0}\"/><c:crosses val=\"autoZero\"/><c:crossBetween val=\"between\"/>", axID, axID + 1);
            }
            else
            {
                catAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"1\" /><c:axPos val=\"b\"/><c:tickLblPos val=\"none\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"autoZero\"/>", axID, axID + 1);
                valAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"r\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"max\"/><c:crossBetween val=\"between\"/>", axID + 1, axID);
            }

            if (_axis.Length == 0)
            {
                _axis = new ExcelChartAxis[2];
            }
            else
            {
                ExcelChartAxis[] newAxis = new ExcelChartAxis[_axis.Length + 2];
                Array.Copy(_axis, newAxis, _axis.Length);
                _axis = newAxis;
            }

            _axis[_axis.Length - 2] = new ExcelChartAxisStandard(this, NameSpaceManager, catAx, "c");
            _axis[_axis.Length - 1] = new ExcelChartAxisStandard(this, NameSpaceManager, valAx, "c");
            foreach (var chart in _plotArea.ChartTypes)
            {
                chart._axis = _axis;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Add a new series to this chart
        /// </summary>
        public void AddSeries(Series series)
        {
            int serCount = ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count();

            if (serCount == MaxSeriesCount)
            {
                throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!");
            }
            // Sourceman 16.04.2015 - Every Series needs to have an order and index element for being processed by Word 2013
            series.Xml.AddFirst(
                new XElement(XName.Get("order", DocX.c.NamespaceName),
                             new XAttribute(XName.Get("val"), (serCount + 1).ToString())));
            series.Xml.AddFirst(
                new XElement(XName.Get("idx", DocX.c.NamespaceName),
                             new XAttribute(XName.Get("val"), (serCount + 1).ToString())));
            ChartXml.Add(series.Xml);
        }
Exemplo n.º 11
0
        internal void SetPivotSource(ExcelPivotTable pivotTableSource)
        {
            PivotTableSource = pivotTableSource;
            XmlElement chart = ChartXml.SelectSingleNode("c:chartSpace/c:chart", NameSpaceManager) as XmlElement;

            var pivotSource = ChartXml.CreateElement("pivotSource", ExcelPackage.schemaChart);

            chart.ParentNode.InsertBefore(pivotSource, chart);
            pivotSource.InnerXml = string.Format("<c:name>[]{0}!{1}</c:name><c:fmtId val=\"0\"/>", PivotTableSource.WorkSheet.Name, pivotTableSource.Name);

            var fmts = ChartXml.CreateElement("pivotFmts", ExcelPackage.schemaChart);

            chart.PrependChild(fmts);
            fmts.InnerXml = "<c:pivotFmt><c:idx val=\"0\"/><c:marker><c:symbol val=\"none\"/></c:marker></c:pivotFmt>";

            Series.AddPivotSerie(pivotTableSource);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Add a new series to this chart
        /// </summary>
        public void AddSeries(Series series)
        {
            var seriesCount = ChartXml.Elements(XName.Get("ser", Document.c.NamespaceName)).Count();

            if (seriesCount >= MaxSeriesCount)
            {
                throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!");
            }

            //To work in Words, all series need an Index and Order.
            var value   = seriesCount + 1;
            var content = new XAttribute(XName.Get("val"), value.ToString());

            series.Xml.AddFirst(new XElement(XName.Get("order", Document.c.NamespaceName), content));
            series.Xml.AddFirst(new XElement(XName.Get("idx", Document.c.NamespaceName), content));
            this.ChartXml.Add(series.Xml);
        }
Exemplo n.º 13
0
        private void CreateNewChart(ExcelDrawings drawings, XmlDocument chartXml = null, eChartType?type = null)
        {
            XmlElement graphFrame = TopNode.OwnerDocument.CreateElement("mc", "AlternateContent", ExcelPackage.schemaMarkupCompatibility);

            graphFrame.SetAttribute("xmlns:mc", ExcelPackage.schemaMarkupCompatibility);
            TopNode.AppendChild(graphFrame);
            graphFrame.InnerXml = string.Format("<mc:Choice xmlns:cx1=\"{1}\" Requires=\"cx1\"><xdr:graphicFrame macro=\"\"><xdr:nvGraphicFramePr><xdr:cNvPr id=\"{0}\" name=\"\"><a:extLst><a:ext uri=\"{{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}}\"><a16:creationId xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\" id=\"{{9FE3C5B3-14FE-44E2-AB27-50960A44C7C4}}\"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"0\" cy=\"0\"/></xdr:xfrm><a:graphic><a:graphicData uri=\"http://schemas.microsoft.com/office/drawing/2014/chartex\"><cx:chart xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"rId1\"/></a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback><xdr:sp macro=\"\" textlink=\"\"><xdr:nvSpPr><xdr:cNvPr id=\"{0}\" name=\"\"/><xdr:cNvSpPr><a:spLocks noTextEdit=\"1\"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x=\"3609974\" y=\"938212\"/><a:ext cx=\"5762625\" cy=\"2743200\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val=\"white\"/></a:solidFill><a:ln w=\"1\"><a:solidFill><a:prstClr val=\"green\"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow=\"clip\" horzOverflow=\"clip\"/><a:lstStyle/><a:p><a:r><a:rPr lang=\"en-US\" sz=\"1100\"/><a:t>This chart isn't available in your version of Excel. Editing this shape or saving this workbook into a different file format will permanently break the chart.</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback>", _id, GetChartExNameSpace(type ?? eChartType.Sunburst));
            TopNode.AppendChild(TopNode.OwnerDocument.CreateElement("clientData", ExcelPackage.schemaSheetDrawings));

            var package = drawings.Worksheet._package.ZipPackage;

            UriChart = GetNewUri(package, "/xl/charts/chartex{0}.xml");

            if (chartXml == null)
            {
                ChartXml = new XmlDocument
                {
                    PreserveWhitespace = ExcelPackage.preserveWhitespace
                };
                LoadXmlSafe(ChartXml, ChartStartXml(type.Value), Encoding.UTF8);
            }
            else
            {
                ChartXml = chartXml;
            }

            // save it to the package
            Part = package.CreatePart(UriChart, ContentTypes.contentTypeChartEx, _drawings._package.Compression);

            StreamWriter streamChart = new StreamWriter(Part.GetStream(FileMode.Create, FileAccess.Write));

            ChartXml.Save(streamChart);
            streamChart.Close();
            package.Flush();

            var chartRelation = drawings.Part.CreateRelationship(UriHelper.GetRelativeUri(drawings.UriDrawing, UriChart), Packaging.TargetMode.Internal, ExcelPackage.schemaChartExRelationships);

            graphFrame.SelectSingleNode("mc:Choice/xdr:graphicFrame/a:graphic/a:graphicData/cx:chart", NameSpaceManager).Attributes["r:id"].Value = chartRelation.Id;
            package.Flush();
            _chartNode      = ChartXml.SelectSingleNode("cx:chartSpace/cx:chart", NameSpaceManager);
            _chartXmlHelper = XmlHelperFactory.Create(NameSpaceManager, _chartNode);
            GetPositionSize();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Returns an reference than containing a list of all descendant elements that match the specified name.
 /// </summary>
 /// <param name="name">The qualified name to match. It is matched against the <c>Name</c> property of the matching node. The special value "*" matches all tags.</param>
 /// <returns>
 /// A list of all matching nodes. If no nodes match name, the returned collection will be empty.
 /// </returns>
 public static IEnumerable <XmlNode> GetElementsByTagName(string name)
 {
     return(ChartXml.GetElementsByTagName(name).Cast <XmlNode>().ToList());
 }
Exemplo n.º 15
0
        private void CreateNewChart(ExcelDrawings drawings, ExcelChart topChart, XmlDocument chartXml = null, eChartType?type = null)
        {
            if (topChart == null)
            {
                XmlElement graphFrame = TopNode.OwnerDocument.CreateElement("graphicFrame", ExcelPackage.schemaSheetDrawings);
                graphFrame.SetAttribute("macro", "");
                TopNode.AppendChild(graphFrame);
                graphFrame.InnerXml = string.Format("<xdr:nvGraphicFramePr><xdr:cNvPr id=\"{0}\" name=\"Chart 1\" /><xdr:cNvGraphicFramePr /></xdr:nvGraphicFramePr><xdr:xfrm><a:off x=\"0\" y=\"0\" /> <a:ext cx=\"0\" cy=\"0\" /></xdr:xfrm><a:graphic><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"><c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"rId1\" />   </a:graphicData>  </a:graphic>", _id);
                TopNode.AppendChild(TopNode.OwnerDocument.CreateElement("clientData", ExcelPackage.schemaSheetDrawings));

                var package = drawings.Worksheet._package.Package;
                UriChart = GetNewUri(package, "/xl/charts/chart{0}.xml");

                if (chartXml == null)
                {
                    ChartXml = new XmlDocument
                    {
                        PreserveWhitespace = ExcelPackage.preserveWhitespace
                    };
                    LoadXmlSafe(ChartXml, ChartStartXml(type.Value), Encoding.UTF8);
                }
                else
                {
                    ChartXml = chartXml;
                }

                // save it to the package
                Part = package.CreatePart(UriChart, "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", _drawings._package.Compression);

                StreamWriter streamChart = new StreamWriter(Part.GetStream(FileMode.Create, FileAccess.Write));
                ChartXml.Save(streamChart);
                streamChart.Close();
                package.Flush();

                var chartRelation = drawings.Part.CreateRelationship(UriHelper.GetRelativeUri(drawings.UriDrawing, UriChart), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/chart");
                graphFrame.SelectSingleNode("a:graphic/a:graphicData/c:chart", NameSpaceManager).Attributes["r:id"].Value = chartRelation.Id;
                package.Flush();
                _chartNode = ChartXml.SelectSingleNode(string.Format("c:chartSpace/c:chart/c:plotArea/{0}", GetChartNodeText()), NameSpaceManager);
            }
            else
            {
                ChartXml  = topChart.ChartXml;
                Part      = topChart.Part;
                _plotArea = topChart.PlotArea;
                UriChart  = topChart.UriChart;
                _axis     = topChart._axis;

                XmlNode preNode = _plotArea.ChartTypes[_plotArea.ChartTypes.Count - 1].ChartNode;
                _chartNode = ((XmlDocument)ChartXml).CreateElement(GetChartNodeText(), ExcelPackage.schemaChart);
                preNode.ParentNode.InsertAfter(_chartNode, preNode);
                if (topChart.Axis.Length == 0)
                {
                    AddAxis();
                }
                string serieXML = GetChartSerieStartXml(type.Value, int.Parse(topChart.Axis[0].Id), int.Parse(topChart.Axis[1].Id), topChart.Axis.Length > 2 ? int.Parse(topChart.Axis[2].Id) : -1);
                _chartNode.InnerXml = serieXML;
            }
            GetPositionSize();
            if (IsType3D())
            {
                Init3DProperties();
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Create a new attribute for this document.
 /// </summary>
 /// <param name="name">Attribute name.</param>
 /// <returns>
 /// <see cref="System.Xml.XmlAttribute" /> reference that contains a new attribute.
 /// </returns>
 public static XmlAttribute CreateAttribute(string name)
 {
     return(ChartXml.CreateAttribute(name));
 }
Exemplo n.º 17
0
 private void Init3DProperties()
 {
     Floor    = new ExcelChartSurface(this, NameSpaceManager, ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:floor", NameSpaceManager));
     BackWall = new ExcelChartSurface(this, NameSpaceManager, ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:backWall", NameSpaceManager));
     SideWall = new ExcelChartSurface(this, NameSpaceManager, ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:sideWall", NameSpaceManager));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Selects the first <see cref="T:System.Xml.XmlNode"/> that matches the XPath expression in the specified node.
 /// </summary>
 /// <param name="root">The root node.</param>
 /// <param name="path">XPath expression.</param>
 /// <returns>
 /// The first <see cref="T:System.Xml.XmlNode"/> that matches the XPath query or <c>null</c> if no matching node is found.
 /// </returns>
 public static XmlNode GetXmlNode(XmlNode root, string path)
 {
     return(root == null?
            ChartXml.SelectSingleNode(path, NamespaceManager) :
                root.SelectSingleNode(path, NamespaceManager));
 }