/// <summary> /// Processes the dynamic chart. /// </summary> /// <param name="dataPart">The data part.</param> /// <param name="tableDataSheetName">Name of the table data sheet.</param> /// <param name="tableData">The table data.</param> /// <param name="presentationWSPart">The presentation ws part.</param> /// <returns></returns> private static bool ProcessDynamicChart(IDataPart dataPart, string tableDataSheetName, TableData tableData, WorksheetPart presentationWSPart) { // TODO: Check this - At the moment, only one chart is supported // Ie. Export the dataPart to a worksheet, which is married with a presentation worksheet, // which contains a single chart (the chart that is cloned). if (dataPart is IPreparable) // Don't think it needs to be preparable anymore. { var chartPart = presentationWSPart.DrawingsPart.ChartParts.FirstOrDefault(); if (chartPart != null) { string id = ChartModel.GetIdOfChartPart(chartPart); // Get the chart we wish to update using a ChartModel, and the last series in the chart, so that we can clone the series. ChartModel chartModel = ChartModel.GetChartModel(presentationWSPart.Worksheet, id); if (chartModel.ChartElements == null) { return(false); } int seriesCount = 0; foreach (OpenXmlCompositeElement chartElement in chartModel.ChartElements) { seriesCount += chartModel.GetSeriesElements(chartElement).Count(); } if (seriesCount == 0) { return(false); } else { return(ProcessDynamicChart(tableDataSheetName, tableData, chartModel)); } } } return(false); }