/// <summary> /// Create Paragraph tree from file /// </summary> private void ParseParagraphs() { Paragraphs = new ParagrafCollection(doc); Segment segItem; SegmentCollection segCollection; Paragraf parItem; int count = doc.MainDocumentPart.Document.Body.Elements <Paragraph>().Count(); for (int i = 0; i < count; i++) { Paragraph p = doc.MainDocumentPart.Document.Body.Elements <Paragraph>().ElementAt(i); segCollection = new SegmentCollection(p); int partCount = p.Elements <Run>().Count(); for (int j = 0; j < partCount; j++) { Run tr = p.Elements <Run>().ElementAt(j); segItem = new Segment(tr); segCollection._add(segItem); } parItem = new Paragraf(p, segCollection); Paragraphs._add(parItem); } }
/// <summary> /// Adding Paragraph to document /// </summary> /// <param name="text">Segment text</param> /// <param name="style">Name of Segment style</param> public void Add(string text, string style = "") { // ----- Create new Paragraph ----- Paragraph p = newParagraph(text, style); doc.MainDocumentPart.Document.Body.AppendChild(p); // ----- Create new Paragraf ----- Paragraf parItem = _newParagraf(p); // create new Paragraf List.Add(parItem); }
private Paragraf _newParagraf(Paragraph p) { Segment segItem; Paragraf parItem; SegmentCollection segCol = new SegmentCollection(p); int partCount = p.Elements <Run>().Count(); for (int j = 0; j < partCount; j++) { Run tr = p.Elements <Run>().ElementAt(j); segItem = new Segment(tr); segCol._add(segItem); } parItem = new Paragraf(p, segCol); return(parItem); }
/// <summary> /// Adding Paragraph to document /// </summary> /// <param name="index">Segment index for inserting</param> /// <param name="text">Segment text</param> /// <param name="style">Name of Segment style</param> public void Insert(int index, string text, string style = "") { // ----- Create new Paragraph ----- Paragraph p = newParagraph(text, style); if (index < 0) { doc.MainDocumentPart.Document.Body.PrependChild(p); } else if (index >= doc.MainDocumentPart.Document.Body.Elements <Paragraph>().Count()) { doc.MainDocumentPart.Document.Body.AppendChild(p); } else { doc.MainDocumentPart.Document.Body.InsertAt(p, index); } // ----- Create new Paragraf ----- Paragraf parItem = _newParagraf(p); // create new Paragraf if (index < 0) { if (List.Count > 0) { List.Insert(0, parItem); } else { List.Add(parItem); } } else if (index >= doc.MainDocumentPart.Document.Body.Elements <Paragraph>().Count()) { List.Add(parItem); } else { List.Insert(index, parItem); } }
/// <summary> /// Internal Function. Adding Paragraph item to ParagraphCollection while Creating Collection Tree. /// </summary> /// <param name="parItem">Paragraph item</param> internal void _add(Paragraf parItem) { List.Add(parItem); }