public TFluent SetShowCategoryName(bool show) { OpenXmlElement dataLabel = this.element.GetOrCreateDataLabelAdjust(); ShowCategoryName showCategoryName = dataLabel.GetFirstChild <ShowCategoryName>() ?? dataLabel.AppendChild(new ShowCategoryName()); showCategoryName.Val = show; return(this.result); }
private void FillSeriesLabels(OpenXmlCompositeElement seriesItem, Column dataColumn) { var labels = seriesItem.FirstElement <DataLabels>(); if (labels == null) { return; } TextProperties defaultTextProperties = labels.FirstElement <TextProperties>(); ChartShapeProperties defaultChartShapeProperties = labels.FirstElement <ChartShapeProperties>(); NumberingFormat defaultNumberingFormat = labels.FirstElement <NumberingFormat>(); ShowLegendKey defaultShowLegendKey = labels.FirstElement <ShowLegendKey>(); ShowValue defaultShowValue = labels.FirstElement <ShowValue>(); ShowCategoryName defaultShowCategoryName = labels.FirstElement <ShowCategoryName>(); ShowSeriesName defaultShowSeriesName = labels.FirstElement <ShowSeriesName>(); ShowPercent defaultShowPercent = labels.FirstElement <ShowPercent>(); ShowBubbleSize defaultShowBubbleSize = labels.FirstElement <ShowBubbleSize>(); ShowLeaderLines defaultShowLeaderLines = labels.FirstElement <ShowLeaderLines>(); DLblsExtension defaultDLblsExtension = labels.FirstElement <DLblsExtension>(); for (int rowNo = 0; rowNo < dataColumn.Data.Count; rowNo++) { if (dataColumn.Data[rowNo] != null) { DataLabel dl = labels.Elements <DataLabel>().FirstOrDefault(l => l.Index != null && l.Index.Val != null && l.Index.Val.Value == rowNo); //if (dl != null) //{ // Delete delete = dl.FirstElement<Delete>(); // if (delete == null || !delete.Val) // { // var tp = dl.FirstElement<TextProperties>(); // if (tp != null) // { // textProperties = tp.CloneNode(true) as TextProperties; // } // labels.RemoveChild<DataLabel>(dl); // dl = null; // } //} if (dl == null) { var newDataLabel = new DataLabel(); DocumentFormat.OpenXml.Drawing.Charts.Index index = new DocumentFormat.OpenXml.Drawing.Charts.Index() { Val = new UInt32Value((uint)rowNo) }; newDataLabel.Index = index; if (defaultNumberingFormat != null) { newDataLabel.Append(defaultNumberingFormat.CloneNode(true)); } if (defaultChartShapeProperties != null) { newDataLabel.Append(defaultChartShapeProperties.CloneNode(true)); } if (defaultTextProperties != null) { newDataLabel.Append(defaultTextProperties.CloneNode(true)); } newDataLabel.Append(defaultShowLegendKey.CloneNode(true)); newDataLabel.Append(defaultShowValue.CloneNode(true)); newDataLabel.Append(defaultShowCategoryName.CloneNode(true)); newDataLabel.Append(defaultShowSeriesName.CloneNode(true)); newDataLabel.Append(defaultShowPercent.CloneNode(true)); newDataLabel.Append(defaultShowBubbleSize.CloneNode(true)); if (defaultShowLeaderLines != null) { newDataLabel.Append(defaultShowLeaderLines.CloneNode(true)); } if (defaultDLblsExtension != null) { newDataLabel.Append(defaultDLblsExtension.CloneNode(true)); } DataLabel lastDataLabel = labels.Elements <DataLabel>().LastOrDefault(l => l.Index != null && l.Index.Val != null && l.Index.Val.Value < rowNo); if (lastDataLabel != null) { labels.InsertAfter(newDataLabel, lastDataLabel); } else { labels.InsertAt(newDataLabel, 0); } } } } }