internal ExcelChartEx(ExcelDrawings drawings, XmlNode drawingsNode, eChartType?type, XmlDocument chartXml = null, ExcelGroupShape parent = null) : base(drawings, drawingsNode, chartXml, parent, "mc:AlternateContent/mc:Choice/xdr:graphicFrame") { ChartType = type.Value; CreateNewChart(drawings, chartXml, type); Init(); }
internal ExcelLineChart(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.Line3D) { Smooth = false; } }
internal ExcelBarChart(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) : base(drawings, node, type, topChart, PivotTableSource, chartXml, parent) { SetChartNodeText(""); if (type.HasValue) { SetTypeProperties(drawings, type.Value); } }
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); } }
internal ExcelChartStandard(ExcelDrawings drawings, XmlNode node, eChartType?type, bool isPivot, ExcelGroupShape parent, string drawingPath = "xdr:graphicFrame", string nvPrPath = "xdr:nvGraphicFramePr/xdr:cNvPr") : base(drawings, node, parent, drawingPath, nvPrPath) { if (type.HasValue) { ChartType = type.Value; } CreateNewChart(drawings, null, null, type); Init(drawings, _chartNode); InitSeries(this, drawings.NameSpaceManager, _chartNode, isPivot); SetTypeProperties(); LoadAxis(); }
private ExcelWorksheet AddSheet(string Name, bool isChart, eChartType?chartType, ExcelPivotTable pivotTableSource = null) { lock (_worksheets) { Name = ValidateFixSheetName(Name); if (GetByName(Name) != null) { throw (new InvalidOperationException(ERR_DUP_WORKSHEET + " : " + Name)); } GetSheetURI(ref Name, out int sheetID, out Uri uriWorksheet, isChart); Packaging.ZipPackagePart worksheetPart = _pck.ZipPackage.CreatePart(uriWorksheet, isChart ? CHARTSHEET_CONTENTTYPE : WORKSHEET_CONTENTTYPE, _pck.Compression); //Create the new, empty worksheet and save it to the package StreamWriter streamWorksheet = new StreamWriter(worksheetPart.GetStream(FileMode.Create, FileAccess.Write)); XmlDocument worksheetXml = CreateNewWorksheet(isChart); worksheetXml.Save(streamWorksheet); _pck.ZipPackage.Flush(); string rel = CreateWorkbookRel(Name, sheetID, uriWorksheet, isChart); int positionID = _worksheets.Count + _pck._worksheetAdd; ExcelWorksheet worksheet; if (isChart) { worksheet = new ExcelChartsheet(_namespaceManager, _pck, rel, uriWorksheet, Name, sheetID, positionID, eWorkSheetHidden.Visible, (eChartType)chartType, pivotTableSource); } else { worksheet = new ExcelWorksheet(_namespaceManager, _pck, rel, uriWorksheet, Name, sheetID, positionID, eWorkSheetHidden.Visible); } _worksheets.Add(_worksheets.Count, worksheet); if (_pck.Workbook.VbaProject != null) { var name = _pck.Workbook.VbaProject.GetModuleNameFromWorksheet(worksheet); _pck.Workbook.VbaProject.Modules.Add(new ExcelVBAModule(worksheet.CodeNameChange) { Name = name, Code = "", Attributes = _pck.Workbook.VbaProject.GetDocumentAttributes(Name, "0{00020820-0000-0000-C000-000000000046}"), Type = eModuleType.Document, HelpContext = 0 }); worksheet.CodeModuleName = name; } return(worksheet); } }
internal ExcelChartStandard(ExcelDrawings drawings, XmlNode drawingsNode, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml = null, ExcelGroupShape parent = null, string drawingPath = "xdr:graphicFrame", string nvPrPath = "xdr:nvGraphicFramePr/xdr:cNvPr") : base(drawings, drawingsNode, chartXml, parent, drawingPath, nvPrPath) { if (type.HasValue) { ChartType = type.Value; } _topChart = topChart; CreateNewChart(drawings, topChart, chartXml, type); Init(drawings, _chartNode); if (chartXml == null) { SetTypeProperties(); } else { ChartType = GetChartType(_chartNode.LocalName); } InitSeries(this, drawings.NameSpaceManager, _chartNode, PivotTableSource != null); if (PivotTableSource != null) { SetPivotSource(PivotTableSource); } if (topChart == null) { LoadAxis(); } else { _axis = topChart.Axis; if (_axis.Length > 0) { XAxis = _axis[0]; YAxis = _axis[1]; } } }
internal ExcelSunburstChart(ExcelDrawings drawings, XmlNode drawingsNode, eChartType?type, XmlDocument chartXml = null, ExcelGroupShape parent = null) : base(drawings, drawingsNode, type, chartXml, parent) { StyleManager.SetChartStyle(Chart.Style.ePresetChartStyle.SunburstChartStyle1); }
internal ExcelStandardChartWithLines(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) : base(drawings, node, type, topChart, PivotTableSource, chartXml, parent) { }
internal static ExcelChart GetNewChart(ExcelDrawings drawings, XmlNode drawNode, eChartType?chartType, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml = null) { switch (chartType) { case eChartType.Area: case eChartType.Area3D: case eChartType.AreaStacked: case eChartType.AreaStacked100: case eChartType.AreaStacked1003D: case eChartType.AreaStacked3D: return(new ExcelAreaChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Pie: case eChartType.PieExploded: case eChartType.Pie3D: case eChartType.PieExploded3D: return(new ExcelPieChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.BarOfPie: case eChartType.PieOfPie: return(new ExcelOfPieChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Doughnut: case eChartType.DoughnutExploded: return(new ExcelDoughnutChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.BarClustered: case eChartType.BarStacked: case eChartType.BarStacked100: case eChartType.BarClustered3D: case eChartType.BarStacked3D: case eChartType.BarStacked1003D: case eChartType.ConeBarClustered: case eChartType.ConeBarStacked: case eChartType.ConeBarStacked100: case eChartType.CylinderBarClustered: case eChartType.CylinderBarStacked: case eChartType.CylinderBarStacked100: case eChartType.PyramidBarClustered: case eChartType.PyramidBarStacked: case eChartType.PyramidBarStacked100: case eChartType.ColumnClustered: case eChartType.ColumnStacked: case eChartType.ColumnStacked100: case eChartType.Column3D: case eChartType.ColumnClustered3D: case eChartType.ColumnStacked3D: case eChartType.ColumnStacked1003D: case eChartType.ConeCol: case eChartType.ConeColClustered: case eChartType.ConeColStacked: case eChartType.ConeColStacked100: case eChartType.CylinderCol: case eChartType.CylinderColClustered: case eChartType.CylinderColStacked: case eChartType.CylinderColStacked100: case eChartType.PyramidCol: case eChartType.PyramidColClustered: case eChartType.PyramidColStacked: case eChartType.PyramidColStacked100: return(new ExcelBarChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.XYScatter: case eChartType.XYScatterLines: case eChartType.XYScatterLinesNoMarkers: case eChartType.XYScatterSmooth: case eChartType.XYScatterSmoothNoMarkers: return(new ExcelScatterChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Line: case eChartType.Line3D: case eChartType.LineMarkers: case eChartType.LineMarkersStacked: case eChartType.LineMarkersStacked100: case eChartType.LineStacked: case eChartType.LineStacked100: return(new ExcelLineChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Bubble: case eChartType.Bubble3DEffect: return(new ExcelBubbleChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Radar: case eChartType.RadarFilled: case eChartType.RadarMarkers: return(new ExcelRadarChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Surface: case eChartType.SurfaceTopView: case eChartType.SurfaceTopViewWireframe: case eChartType.SurfaceWireframe: return(new ExcelSurfaceChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.StockHLC: case eChartType.StockOHLC: case eChartType.StockVHLC: case eChartType.StockVOHLC: return(new ExcelStockChart(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); case eChartType.Sunburst: return(new ExcelSunburstChart(drawings, drawNode, chartType, chartXml)); case eChartType.Treemap: return(new ExcelTreemapChart(drawings, drawNode, chartType, chartXml)); case eChartType.BoxWhisker: return(new ExcelBoxWhiskerChart(drawings, drawNode, chartType, chartXml)); case eChartType.Histogram: case eChartType.Pareto: return(new ExcelHistogramChart(drawings, drawNode, chartType, chartXml)); case eChartType.Waterfall: return(new ExcelWaterfallChart(drawings, drawNode, chartType, chartXml)); case eChartType.Funnel: return(new ExcelFunnelChart(drawings, drawNode, chartType, chartXml)); case eChartType.RegionMap: return(new ExcelRegionMapChart(drawings, drawNode, chartType, chartXml)); default: return(new ExcelChartStandard(drawings, drawNode, chartType, topChart, PivotTableSource, chartXml)); } }
internal ExcelScatterChart(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) : base(drawings, node, type, topChart, PivotTableSource, chartXml, parent) { SetTypeProperties(); }
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(); }
internal ExcelRegionMapChart(ExcelDrawings drawings, XmlNode drawingsNode, eChartType?type, XmlDocument chartXml = null, ExcelGroupShape parent = null) : base(drawings, drawingsNode, type, chartXml, parent) { Series.Init(this, NameSpaceManager, TopNode, false, base.Series._list); StyleManager.SetChartStyle(Chart.Style.ePresetChartStyle.RegionMapChartStyle1); }
internal ExcelSurfaceChart(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) : base(drawings, node, type, topChart, PivotTableSource, chartXml, parent) { Init(); }
internal ExcelBubbleChart(ExcelDrawings drawings, XmlNode node, eChartType?type, ExcelChart topChart, ExcelPivotTable PivotTableSource, XmlDocument chartXml, ExcelGroupShape parent = null) : base(drawings, node, type, topChart, PivotTableSource, chartXml, parent) { ShowNegativeBubbles = false; BubbleScale = 100; }
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(); } }