Example #1
0
 /// <summary>
 /// Tries to find an IPart from the list that matches with the provided IDataPart.
 /// ExportException if no matches or more than one match.
 /// Also calls IPart.Valid method and an ExportException will be thrown if the match proves to be invalid
 /// </summary>
 /// <param name="dataPart">The IDataPart to try and find an IPart match on</param>
 /// <param name="parts">The parts.</param>
 /// <returns>
 /// The IPart match
 /// </returns>
 private static IEnumerable <ExportPart> SafePartMatch(IDataPart dataPart, IEnumerable <ExportPart> parts)
 {
     // match on PartId
     foreach (var exportPart in from p in parts
              where p.PartId.CompareTo(dataPart.PartId) == 0
              select p)
     {
         // make sure its valid
         string exportPartErrorMsg = null;
         if (exportPart.Valid(out exportPartErrorMsg))
         {
             yield return(exportPart);
         }
     }
 }
Example #2
0
        internal ExportTripleSet(IDataPart dataPart, ExportPart exportPart, Template template)
        {
            if (dataPart == null)
            {
                throw new ArgumentNullException("dataPart");
            }
            if (exportPart == null)
            {
                throw new ArgumentNullException("exportPart");
            }
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            this.DataPart = dataPart;
            this.Part     = exportPart;
            this.Template = template;
        }
        /// <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);
        }