Exemplo n.º 1
0
        /// <summary>
        /// Replaces the cells from a table (tbl).
        /// Algorithm for a slide template containing multiple tables.
        /// </summary>
        /// <param name="slideTemplate">The slide template that contains the table(s).</param>
        /// <param name="tableTemplate">The table (tbl) to use, should be inside the slide template.</param>
        /// <param name="rows">The rows to replace the table's cells.</param>
        /// <param name="existingSlides">Existing slides created for the other tables inside the slide template.</param>
        /// <returns>The newly created slides if any.</returns>
        public static IEnumerable <PowerpointSlide> ReplaceTable_Multiple(PowerpointSlide slideTemplate, PowerpointTable tableTemplate, IList <PowerpointTable.Cell[]> rows, List <PowerpointSlide> existingSlides)
        {
            List <PowerpointSlide> slidesCreated = new List <PowerpointSlide>();

            string tag = tableTemplate.Title;

            PowerpointSlide lastSlide = slideTemplate;

            if (existingSlides.Count > 0)
            {
                lastSlide = existingSlides.Last();
            }

            PowerpointSlide lastSlideTemplate = lastSlide.Clone();

            foreach (PowerpointSlide slide in existingSlides)
            {
                PowerpointTable table = slide.FindTables(tag).First();
                List <PowerpointTable.Cell[]> remainingRows = table.SetRows(rows);
                rows = remainingRows;
            }

            // Force SetRows() at least once if there is no existingSlides
            // this means we are being called by ReplaceTable_One()
            bool loopOnce = existingSlides.Count == 0;

            while (loopOnce || rows.Count > 0)
            {
                PowerpointSlide newSlide = lastSlideTemplate.Clone();
                PowerpointTable table    = newSlide.FindTables(tag).First();
                List <PowerpointTable.Cell[]> remainingRows = table.SetRows(rows);
                rows = remainingRows;

                PowerpointSlide.InsertAfter(newSlide, lastSlide);
                lastSlide = newSlide;
                slidesCreated.Add(newSlide);

                if (loopOnce)
                {
                    loopOnce = false;
                }
            }

            lastSlideTemplate.Remove();

            return(slidesCreated);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Replaces the cells from a table (tbl).
 /// Algorithm for a slide template containing one table.
 /// </summary>
 public static IEnumerable <PowerpointSlide> ReplaceTable_One(PowerpointSlide slideTemplate, PowerpointTable tableTemplate, IList <PowerpointTable.Cell[]> rows)
 {
     return(ReplaceTable_Multiple(slideTemplate, tableTemplate, rows, new List <PowerpointSlide>()));
 }