コード例 #1
0
        public virtual Paragraph InsertParagraph(int index, string text, bool trackChanges, Formatting formatting)
        {
            var newParagraph = new Paragraph(this.Document, new XElement(DocX.w + "p"), index);

            newParagraph.InsertText(0, text, trackChanges, formatting);

            var firstPar = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            if (firstPar != null)
            {
                var splitIndex = index - firstPar._startIndex;
                if (splitIndex > 0)
                {
                    var splitParagraph = HelperFunctions.SplitParagraph(firstPar, splitIndex);
                    firstPar.Xml.ReplaceWith(splitParagraph[0], newParagraph.Xml, splitParagraph[1]);
                }
                else
                {
                    firstPar.Xml.ReplaceWith(newParagraph.Xml, firstPar.Xml);
                }
            }
            else
            {
                this.Xml.Add(newParagraph);
            }

            this.SetParentContainer(newParagraph);
            return(newParagraph);
        }
コード例 #2
0
        public virtual Paragraph InsertParagraph(int index, Paragraph p)
        {
            var newXElement = new XElement(p.Xml);

            p.Xml = newXElement;

            var paragraph = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            if (paragraph == null)
            {
                Xml.Add(p.Xml);
            }
            else
            {
                var split = HelperFunctions.SplitParagraph(paragraph, index - paragraph._startIndex);

                paragraph.Xml.ReplaceWith
                (
                    split[0],
                    newXElement,
                    split[1]
                );
            }
            this.SetParentContainer(p);
            return(p);
        }
コード例 #3
0
        public virtual List InsertList(int index, List list)
        {
            var p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            var split    = HelperFunctions.SplitParagraph(p, index - p._startIndex);
            var elements = new List <XElement> {
                split[0]
            };

            elements.AddRange(list.Items.Select(i => new XElement(i.Xml)));
            elements.Add(split[1]);
            p.Xml.ReplaceWith(elements.ToArray());

            return(list);
        }
コード例 #4
0
        public virtual Table InsertTable(int index, Table t)
        {
            var p = HelperFunctions.GetFirstParagraphEffectedByInsert(this.Document, index);

            var split       = HelperFunctions.SplitParagraph(p, index - p._startIndex);
            var newXElement = new XElement(t.Xml);

            p.Xml.ReplaceWith(split[0], newXElement, split[1]);

            var newTable = new Table(this.Document, newXElement);

            newTable.Design      = t.Design;
            newTable.PackagePart = this.PackagePart;
            return(newTable);
        }
コード例 #5
0
        public virtual Table InsertTable(int index, int rowCount, int columnCount)
        {
            var newTable = HelperFunctions.CreateTable(rowCount, columnCount);

            var p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            if (p == null)
            {
                Xml.Elements().First().AddFirst(newTable);
            }
            else
            {
                var split = HelperFunctions.SplitParagraph(p, index - p._startIndex);
                p.Xml.ReplaceWith(split[0], newTable, split[1]);
            }

            var table = new Table(this.Document, newTable);

            table.PackagePart = this.PackagePart;
            return(table);
        }