Example #1
0
        /// <summary>
        /// Fill a textbox with a text
        /// </summary>
        /// <param name="textbox">textbox to fill</param>
        /// <param name="newText">text to fill</param>
        public static void FillTextBox(this WordprocessingShape textbox, string newText)
        {
            // Get Textbox content
            TextBoxContent content = textbox.Descendants <TextBoxContent>().FirstOrDefault();

            if (content != null)
            {
                // Retrieve old paragraph to get the current style of text
                Paragraph oldParagraph = content.Elements <Paragraph>().FirstOrDefault();

                // Create a new text
                var paragraph = CreateParagraph(oldParagraph, newText);

                // Replace old text with new one
                if (oldParagraph != null)
                {
                    content.ReplaceChild(paragraph, oldParagraph);
                }
                else
                {
                    content.Append(paragraph);
                }
            }
        }