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); }
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 }); }
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); }
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); }
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 }); }
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); }
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); }
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); }
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 }); }
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); }