Пример #1
0
        public static void RemoveDefaultPagination(OpenXmlElement element)
        {
            Paragraph mainParagraph = element.Elements <Paragraph>().First();
            Run       mainRun       = mainParagraph.Elements <Run>().ElementAt(1);
            Picture   pic           = mainRun.Elements <Picture>().First();

            V.Shape        sh                 = pic.Elements <V.Shape>().First();
            V.TextBox      textBox            = sh.Elements <V.TextBox>().First();
            TextBoxContent textBoxContent     = textBox.Elements <TextBoxContent>().First();
            Paragraph      paginatedParagraph = textBoxContent.Elements <Paragraph>().First();
            //paginatedParagraph.RemoveAllChildren();
            List <Run> paginatedRuns = paginatedParagraph.Elements <Run>().ToList();
            List <Run> newRuns       = paginatedRuns.GetRange(0, 7);

            var indexValue = 0;

            foreach (Run item in newRuns)
            {
                item.RemoveAllChildren();
                item.Remove();
                //RunProperties runProperties4 = new RunProperties();
                //FontSize fontSize2 = new FontSize() { Val = "16" };

                //runProperties4.Append(fontSize2);
                //Text text2 = new Text();
                //text2.Text = "P";
                //item.Append(runProperties4);
                //item.Append(text2);
                //item.Remove();
            }
        }
Пример #2
0
        /// <summary>
        /// Add text box content
        /// </summary>
        /// <param name="textBoxContent"></param>
        /// <returns></returns>
        private string AddTextBoxContent(TextBoxContent textBoxContent)
        {
            string result = "";

            foreach (OpenXmlElement element in textBoxContent.Elements())
            {
                if (element is Paragraph)
                {
                    result += AddParagraph((Paragraph)element);
                }
            }

            return(result);
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Add text box content
        /// </summary>
        /// <param name="textBoxContent"></param>
        /// <returns></returns>
        private string AddTextBoxContent(TextBoxContent textBoxContent)
        {
            string result = "";

            foreach (OpenXmlElement element in textBoxContent.Elements())
                if (element is Paragraph)
                    result += AddParagraph((Paragraph)element);
 
            return result;
        }