Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
 /// <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);
 }