/// <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 <PptxSlide> ReplaceTable_Multiple(PptxSlide slideTemplate, PptxTable tableTemplate, IList <PptxTable.Cell[]> rows, List <PptxSlide> existingSlides) { List <PptxSlide> slidesCreated = new List <PptxSlide>(); string tag = tableTemplate.Title; PptxSlide lastSlide = slideTemplate; if (existingSlides.Count > 0) { lastSlide = existingSlides.Last(); } PptxSlide lastSlideTemplate = lastSlide.Clone(); foreach (PptxSlide slide in existingSlides) { PptxTable table = slide.FindTables(tag).First(); List <PptxTable.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) { PptxSlide newSlide = lastSlideTemplate.Clone(); PptxTable table = newSlide.FindTables(tag).First(); List <PptxTable.Cell[]> remainingRows = table.SetRows(rows); rows = remainingRows; PptxSlide.InsertAfter(newSlide, lastSlide); lastSlide = newSlide; slidesCreated.Add(newSlide); if (loopOnce) { loopOnce = false; } } lastSlideTemplate.Remove(); return(slidesCreated); }
/// <summary> /// Replaces the cells from a table (tbl). /// Algorithm for a slide template containing one table. /// </summary> public static IEnumerable <PptxSlide> ReplaceTable_One(PptxSlide slideTemplate, PptxTable tableTemplate, IList <PptxTable.Cell[]> rows) { return(ReplaceTable_Multiple(slideTemplate, tableTemplate, rows, new List <PptxSlide>())); }
/// <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<PptxSlide> ReplaceTable_Multiple(PptxSlide slideTemplate, PptxTable tableTemplate, IList<PptxTable.Cell[]> rows, List<PptxSlide> existingSlides) { List<PptxSlide> slidesCreated = new List<PptxSlide>(); string tag = tableTemplate.Title; PptxSlide lastSlide = slideTemplate; if (existingSlides.Count > 0) { lastSlide = existingSlides.Last(); } PptxSlide lastSlideTemplate = lastSlide.Clone(); foreach (PptxSlide slide in existingSlides) { PptxTable table = slide.FindTables(tag).First(); List<PptxTable.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) { PptxSlide newSlide = lastSlideTemplate.Clone(); PptxTable table = newSlide.FindTables(tag).First(); List<PptxTable.Cell[]> remainingRows = table.SetRows(rows); rows = remainingRows; PptxSlide.InsertAfter(newSlide, lastSlide); lastSlide = newSlide; slidesCreated.Add(newSlide); if (loopOnce) loopOnce = false; } lastSlideTemplate.Remove(); return slidesCreated; }
/// <summary> /// Replaces a text (tag) by another inside the slide given a PptxTable.Cell. /// This is a convenient method that overloads the original ReplaceTag() method. /// </summary> /// <param name="tagPair">The tag/new text, BackgroundPicture is ignored.</param> /// <param name="replacementType">The type of replacement to perform.</param> public void ReplaceTag(PptxTable.Cell tagPair, ReplacementType replacementType) { this.ReplaceTag(tagPair.Tag, tagPair.NewText, replacementType); }
/// <summary> /// Replaces the cells from a table (tbl). /// Algorithm for a slide template containing one table. /// </summary> public static IEnumerable<PptxSlide> ReplaceTable_One(PptxSlide slideTemplate, PptxTable tableTemplate, IList<PptxTable.Cell[]> rows) { return ReplaceTable_Multiple(slideTemplate, tableTemplate, rows, new List<PptxSlide>()); }