/// <summary> /// Replaces a tag inside a given table cell (a:tc). /// </summary> /// <param name="slide">The PptxSlide.</param> /// <param name="tc">The table cell (a:tc).</param> /// <param name="cell">Contains the tag, the new text and a picture.</param> /// <returns><c>true</c> if a tag has been found and replaced, <c>false</c> otherwise.</returns> private static bool ReplaceTag(PptxSlide slide, A.TableCell tc, Cell cell) { bool replacedAtLeastOnce = false; // a:p foreach (A.Paragraph p in tc.Descendants <A.Paragraph>()) { bool replaced = PptxParagraph.ReplaceTag(p, cell.Tag, cell.NewText); if (replaced) { replacedAtLeastOnce = true; // a:tcPr if (cell.Picture != null) { A.TableCellProperties tcPr = tc.GetFirstChild <A.TableCellProperties>(); SetTableCellPropertiesWithBackgroundPicture(slide, tcPr, cell.Picture); } } } return(replacedAtLeastOnce); }
/// <summary> /// Replaces a text (tag) by another inside the slide. /// </summary> /// <param name="tag">The tag to replace by newText, if null or empty do nothing; tag is a regex string.</param> /// <param name="newText">The new text to replace the tag with, if null replaced by empty string.</param> /// <param name="replacementType">The type of replacement to perform.</param> public void ReplaceTag(string tag, string newText, ReplacementType replacementType) { foreach (A.Paragraph p in this.slidePart.Slide.Descendants <A.Paragraph>()) { switch (replacementType) { case ReplacementType.Global: PptxParagraph.ReplaceTag(p, tag, newText); break; case ReplacementType.NoTable: var tables = p.Ancestors <A.Table>(); if (!tables.Any()) { // If the paragraph has no table ancestor PptxParagraph.ReplaceTag(p, tag, newText); } break; } } this.Save(); }