예제 #1
0
        /// <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:
                    PowerpointParagraph.ReplaceTag(p, tag, newText);
                    break;

                case ReplacementType.NoTable:
                    var tables = p.Ancestors <A.Table>();
                    if (!tables.Any())
                    {
                        // If the paragraph has no table ancestor
                        PowerpointParagraph.ReplaceTag(p, tag, newText);
                    }
                    break;
                }
            }

            this.Save();
        }
예제 #2
0
        /// <summary>
        /// Replaces a tag inside a given table cell (a:tc).
        /// </summary>
        /// <param name="slide">The PowerpointSlide.</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(PowerpointSlide slide, A.TableCell tc, Cell cell)
        {
            bool replacedAtLeastOnce = false;

            // a:p
            foreach (A.Paragraph p in tc.Descendants <A.Paragraph>())
            {
                bool replaced = PowerpointParagraph.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);
        }
예제 #3
0
        /// <summary>
        /// Gets all the notes associated with the slide.
        /// </summary>
        /// <returns>All the notes.</returns>
        /// <remarks>
        /// <see href="http://msdn.microsoft.com/en-us/library/office/gg278319.aspx">Working with Notes Slides</see>
        /// </remarks>
        public IEnumerable <string> GetNotes()
        {
            var notes = new List <string>();

            if (this.slidePart.NotesSlidePart != null)
            {
                notes.AddRange(this.slidePart.NotesSlidePart.NotesSlide.Descendants <A.Paragraph>().Select(p => PowerpointParagraph.GetTexts(p)));
            }
            return(notes);
        }
예제 #4
0
        /// <summary>
        /// Gets the slide title if any.
        /// </summary>
        /// <returns>The title or an empty string.</returns>
        public string GetTitle()
        {
            string title = string.Empty;

            // Find the title if any
            Shape titleShape = this.slidePart.Slide.Descendants <Shape>().FirstOrDefault(sp => IsShapeATitle(sp));

            if (titleShape != null)
            {
                title = string.Join(" ", titleShape.Descendants <A.Paragraph>().Select(p => PowerpointParagraph.GetTexts(p)));
            }

            return(title);
        }
예제 #5
0
 /// <summary>
 /// Gets all the texts found inside the slide.
 /// </summary>
 /// <returns>The list of texts detected into the slide.</returns>
 /// <remarks>
 /// Some strings inside the array can be empty, this happens when all A.Text from a paragraph are empty
 /// <see href="http://msdn.microsoft.com/en-us/library/office/cc850836">How to: Get All the Text in a Slide in a Presentation</see>
 /// </remarks>
 public IEnumerable <string> GetTexts()
 {
     return(this.slidePart.Slide.Descendants <A.Paragraph>().Select(p => PowerpointParagraph.GetTexts(p)));
 }