예제 #1
0
        public override Paragraph AppendParagraph()
        {
            var pPr = new XElement(XName.Get("pPr", Namespaces.w.NamespaceName));
            var p   = new XElement(XName.Get("p", Namespaces.w.NamespaceName), pPr);

            var paragraph = new Paragraph(p, this);

            if (hostingParagraph == null)             // i.e. this is the last document section
            {
                var lastParagraph = sectionParagraphs.LastOrDefault();

                if (lastParagraph == null)
                {
                    Xml.AddBeforeSelf(p);
                }
                else
                {
                    lastParagraph.Xml.AddAfterSelf(p);
                }
            }
            else
            {
                Xml.Remove();
                pPr.Add(Xml);
                hostingParagraph.Xml.AddAfterSelf(p);
                hostingParagraph = paragraph;
            }

            sectionParagraphs.Add(paragraph);

            return(paragraph);
        }
예제 #2
0
        public override Table AppendTable(CreateTableParameters parameters)
        {
            Document.Styles.EnsureStyle(parameters.Style, StyleType.Table);
            var table = Table.Create(parameters, this);

            if (hostingParagraph == null)             // i.e. this is the last document section
            {
                var lastParagraph = sectionParagraphs.LastOrDefault();

                if (lastParagraph == null)
                {
                    Xml.AddBeforeSelf(table.Xml);
                }
                else
                {
                    lastParagraph.Xml.AddAfterSelf(table.Xml);
                }
            }
            else
            {
                Xml.Remove();

                var newSectionLastParagraphXml = new XElement(
                    XName.Get("p", Namespaces.w.NamespaceName),
                    new XElement(XName.Get("pPr", Namespaces.w.NamespaceName), Xml));

                hostingParagraph.Xml.AddAfterSelf(newSectionLastParagraphXml);
                hostingParagraph.Xml.AddAfterSelf(table.Xml);
                var newSectionLastParagraph = new Paragraph(newSectionLastParagraphXml, this);
                hostingParagraph = newSectionLastParagraph;
                sectionParagraphs.Add(newSectionLastParagraph);
            }

            return(table);
        }
예제 #3
0
        public virtual Paragraph InsertParagraphBeforeSelf(Paragraph p)
        {
            Xml.AddBeforeSelf(p.Xml);
            XElement newlyInserted = Xml.ElementsBeforeSelf().First();

            p.Xml = newlyInserted;

            return(p);
        }
예제 #4
0
        public virtual Table InsertTableBeforeSelf(int rowCount, int columnCount)
        {
            XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);

            Xml.AddBeforeSelf(newTable);
            XElement newlyInserted = Xml.ElementsBeforeSelf().Last();

            return(new Table(Document, newlyInserted));
        }
예제 #5
0
        public virtual Table InsertTableBeforeSelf(Table t)
        {
            Xml.AddBeforeSelf(t.Xml);
            XElement newlyInserted = Xml.ElementsBeforeSelf().Last();

            //Dmitchern
            return(new Table(Document, newlyInserted)); //return new table, dont affect parameter table

            //t.Xml = newlyInserted;
            //return t;
        }
예제 #6
0
        public virtual Paragraph InsertParagraphBeforeSelf(string text, bool trackChanges, Formatting formatting)
        {
            XElement newParagraph = new XElement
                                    (
                XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName)), HelperFunctions.FormatInput(text, formatting.Xml)
                                    );

            if (trackChanges)
            {
                newParagraph = Paragraph.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
            }

            Xml.AddBeforeSelf(newParagraph);
            XElement newlyInserted = Xml.ElementsBeforeSelf().Last();

            return(new Paragraph(Document, newlyInserted, -1));
        }
예제 #7
0
        public virtual void InsertPageBreakBeforeSelf()
        {
            XElement p = new XElement
                         (
                XName.Get("p", DocX.w.NamespaceName),
                new XElement
                (
                    XName.Get("r", DocX.w.NamespaceName),
                    new XElement
                    (
                        XName.Get("br", DocX.w.NamespaceName),
                        new XAttribute(XName.Get("type", DocX.w.NamespaceName), "page")
                    )
                )
                         );

            Xml.AddBeforeSelf(p);
        }