Exemplo n.º 1
0
        /// <summary>
        ///     Adds a new paragraph in collection.
        /// </summary>
        /// <returns>Added <see cref="SCParagraph" /> instance.</returns>
        public IParagraph Add()
        {
            // Create a new paragraph from the last paragraph and insert at the end
            A.Paragraph lastAParagraph = this.paragraphs.Value.Last().AParagraph;
            A.Paragraph newAParagraph  = (A.Paragraph)lastAParagraph.CloneNode(true);
            lastAParagraph.InsertAfterSelf(newAParagraph);

            var newParagraph = new SCParagraph(newAParagraph, this.textBox)
            {
                Text = string.Empty
            };

            this.paragraphs.Reset();

            return(newParagraph);
        }
Exemplo n.º 2
0
 private static void ModifyPowerPointCellTextContent(OpenXmlElement cell, string txt)
 {
     OXD.TextBody textbody = cell?.Descendants <OXD.TextBody>().FirstOrDefault();
     if (textbody == null)
     {
         return;
     }
     OXD.TextBody  final_textbody = textbody.CloneNode(true) as OXD.TextBody;
     OXD.Paragraph paragraph      = final_textbody?.Descendants <OXD.Paragraph>().FirstOrDefault();
     if (null != paragraph)
     {
         OXD.Paragraph final_paragraph = paragraph.CloneNode(true) as OXD.Paragraph;
         ModifyPowerPointParagraphTextContent(final_paragraph, txt);
         final_textbody.ReplaceChild(final_paragraph, paragraph);
     }
     cell.ReplaceChild(final_textbody, textbody);
 }
Exemplo n.º 3
0
        // Moves a paragraph range in a TextBody shape in the source document
        // to another TextBody shape in the target document.
        public static void MoveParagraphToPresentation(string sourceFile, string targetFile)
        {
            // Open the source file as read/write.
            using (PresentationDocument sourceDoc = PresentationDocument.Open(sourceFile, true))
            {
                // Open the target file as read/write.
                using (PresentationDocument targetDoc = PresentationDocument.Open(targetFile, true))
                {
                    // Get the first slide in the source presentation.
                    SlidePart slide1 = GetFirstSlide(sourceDoc);

                    // Get the first TextBody shape in it.
                    TextBody textBody1 = slide1.Slide.Descendants <TextBody>().First();

                    // Get the first paragraph in the TextBody shape.
                    // Note: "Drawing" is the alias of namespace DocumentFormat.OpenXml.Drawing
                    Drawing.Paragraph p1 = textBody1.Elements <Drawing.Paragraph>().First();

                    // Get the first slide in the target presentation.
                    SlidePart slide2 = GetFirstSlide(targetDoc);

                    // Get the first TextBody shape in it.
                    TextBody textBody2 = slide2.Slide.Descendants <TextBody>().First();

                    // Clone the source paragraph and insert the cloned. paragraph into the target TextBody shape.
                    // Passing "true" creates a deep clone, which creates a copy of the
                    // Paragraph object and everything directly or indirectly referenced by that object.
                    textBody2.Append(p1.CloneNode(true));

                    // Remove the source paragraph from the source file.
                    textBody1.RemoveChild <Drawing.Paragraph>(p1);

                    // Replace the removed paragraph with a placeholder.
                    textBody1.AppendChild <Drawing.Paragraph>(new Drawing.Paragraph());

                    // Save the slide in the source file.
                    slide1.Slide.Save();

                    // Save the slide in the target file.
                    slide2.Slide.Save();
                }
            }
        }
Exemplo n.º 4
0
 private static void ModifyPowerPointCellTextContent(OXD.TableCell cell, string txt)
 {
     if (null != cell)
     {
         OXD.TextBody textbody = cell.Descendants <OXD.TextBody>().FirstOrDefault();
         if (null != textbody)
         {
             OXD.TextBody  final_textbody = textbody.CloneNode(true) as OXD.TextBody;
             OXD.Paragraph paragraph      = final_textbody.Descendants <OXD.Paragraph>().FirstOrDefault();
             if (null != paragraph)
             {
                 OXD.Paragraph final_paragraph = paragraph.CloneNode(true) as OXD.Paragraph;
                 ModifyPowerPointParagraphTextContent(final_paragraph, txt);
                 final_textbody.ReplaceChild <OXD.Paragraph>(final_paragraph, paragraph);
             }
             cell.ReplaceChild <OXD.TextBody>(final_textbody, textbody);
         }
     }
 }