SplitParagraph() static private method

static private SplitParagraph ( Paragraph p, int index ) : System.Xml.Linq.XElement[]
p Paragraph
index int
return System.Xml.Linq.XElement[]
Beispiel #1
0
        public virtual Paragraph InsertParagraph(int index, Paragraph p)
        {
            XElement newXElement = new XElement(p.Xml);

            p.Xml = newXElement;

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

            if (paragraph == null)
            {
                Xml.Add(p.Xml);
            }
            else
            {
                XElement[] split = HelperFunctions.SplitParagraph(paragraph, index - paragraph.startIndex);

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

            GetParent(p);

            return(p);
        }
Beispiel #2
0
        public Table InsertTable(int index, int rowCount, int columnCount)
        {
            XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);

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

            if (p == null)
            {
                Xml.Elements().First().AddFirst(newTable);
            }

            else
            {
                XElement[] split = HelperFunctions.SplitParagraph(p, index - p.startIndex);

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


            return(new Table(Document, newTable)
            {
                mainPart = mainPart
            });
        }
Beispiel #3
0
        public virtual Paragraph InsertParagraph(int index, string text, bool trackChanges, Formatting formatting)
        {
            Paragraph paragraph = new Paragraph(base.Document, new XElement(DocX.w + "p"), index);

            paragraph.InsertText(0, text, trackChanges, formatting);
            Paragraph firstParagraphEffectedByInsert = HelperFunctions.GetFirstParagraphEffectedByInsert(base.Document, index);

            if (firstParagraphEffectedByInsert != null)
            {
                int num = index - firstParagraphEffectedByInsert.startIndex;
                if (num <= 0)
                {
                    firstParagraphEffectedByInsert.Xml.ReplaceWith(paragraph.Xml, firstParagraphEffectedByInsert.Xml);
                }
                else
                {
                    XElement[] array = HelperFunctions.SplitParagraph(firstParagraphEffectedByInsert, num);
                    firstParagraphEffectedByInsert.Xml.ReplaceWith(array[0], paragraph.Xml, array[1]);
                }
            }
            else
            {
                base.Xml.Add(paragraph);
            }
            GetParent(paragraph);
            return(paragraph);
        }
Beispiel #4
0
        public virtual Paragraph InsertParagraph(int index, string text, bool trackChanges, Formatting formatting)
        {
            Paragraph newParagraph = new Paragraph(Document, new XElement(DocX.w + "p"), index);

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

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

            if (firstPar != null)
            {
                XElement[] splitParagraph = HelperFunctions.SplitParagraph(firstPar, index - firstPar.startIndex);

                firstPar.Xml.ReplaceWith
                (
                    splitParagraph[0],
                    newParagraph.Xml,
                    splitParagraph[1]
                );
            }

            else
            {
                Xml.Add(newParagraph);
            }

            GetParent(newParagraph);

            return(newParagraph);
        }
Beispiel #5
0
        public Table InsertTable(int index, Table t)
        {
            Paragraph firstParagraphEffectedByInsert = HelperFunctions.GetFirstParagraphEffectedByInsert(base.Document, index);

            XElement[] array    = HelperFunctions.SplitParagraph(firstParagraphEffectedByInsert, index - firstParagraphEffectedByInsert.startIndex);
            XElement   xElement = new XElement(t.Xml);

            firstParagraphEffectedByInsert.Xml.ReplaceWith(array[0], xElement, array[1]);
            return(new Table(base.Document, xElement)
            {
                mainPart = mainPart,
                Design = t.Design
            });
        }
Beispiel #6
0
        public List InsertList(int index, List list)
        {
            Paragraph p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            XElement[] 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);
        }
Beispiel #7
0
        public virtual Paragraph InsertParagraph(int index, Paragraph p)
        {
            XElement  xElement2 = p.Xml = new XElement(p.Xml);
            Paragraph firstParagraphEffectedByInsert = HelperFunctions.GetFirstParagraphEffectedByInsert(base.Document, index);

            if (firstParagraphEffectedByInsert == null)
            {
                base.Xml.Add(p.Xml);
            }
            else
            {
                XElement[] array = HelperFunctions.SplitParagraph(firstParagraphEffectedByInsert, index - firstParagraphEffectedByInsert.startIndex);
                firstParagraphEffectedByInsert.Xml.ReplaceWith(array[0], xElement2, array[1]);
            }
            GetParent(p);
            return(p);
        }
Beispiel #8
0
        public List InsertList(int index, List list)
        {
            Paragraph firstParagraphEffectedByInsert = HelperFunctions.GetFirstParagraphEffectedByInsert(base.Document, index);

            XElement[]      array = HelperFunctions.SplitParagraph(firstParagraphEffectedByInsert, index - firstParagraphEffectedByInsert.startIndex);
            List <XElement> list2 = new List <XElement>
            {
                array[0]
            };

            list2.AddRange(from i in list.Items
                           select new XElement(i.Xml));
            list2.Add(array[1]);
            XElement xml = firstParagraphEffectedByInsert.Xml;

            object[] content = list2.ToArray();
            xml.ReplaceWith(content);
            return(list);
        }
Beispiel #9
0
        public Table InsertTable(int index, int rowCount, int columnCount)
        {
            XElement  xElement = HelperFunctions.CreateTable(rowCount, columnCount);
            Paragraph firstParagraphEffectedByInsert = HelperFunctions.GetFirstParagraphEffectedByInsert(base.Document, index);

            if (firstParagraphEffectedByInsert == null)
            {
                base.Xml.Elements().First().AddFirst(xElement);
            }
            else
            {
                XElement[] array = HelperFunctions.SplitParagraph(firstParagraphEffectedByInsert, index - firstParagraphEffectedByInsert.startIndex);
                firstParagraphEffectedByInsert.Xml.ReplaceWith(array[0], xElement, array[1]);
            }
            return(new Table(base.Document, xElement)
            {
                mainPart = mainPart
            });
        }
Beispiel #10
0
        public Table InsertTable(int index, Table t)
        {
            Paragraph p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            XElement[] split       = HelperFunctions.SplitParagraph(p, index - p.startIndex);
            XElement   newXElement = new XElement(t.Xml);

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

            Table newTable = new Table(Document, newXElement);

            newTable.Design = t.Design;

            return(newTable);
        }