/// <summary> /// Create a document and insert Sections into it. /// </summary> public static void InsertSections() { Console.WriteLine("\tInsertSections()"); // Create a document. using (DocX document = DocX.Create(SectionSample.SectionSampleOutputDirectory + @"InsertSections.docx")) { document.PageLayout.Orientation = Orientation.Portrait; // Add a title document.InsertParagraph("Inserting sections").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center; // Add 2 paragraphs document.InsertParagraph("This is the first paragraph."); document.InsertParagraph("This is the second paragraph."); // Add a paragraph and a section break. document.InsertSection(); // Add a new paragraph document.InsertParagraph("This is the third paragraph, in a new section."); // Add a paragraph and a page break. document.InsertSectionPageBreak(); document.PageLayout.Orientation = Orientation.Landscape; document.InsertParagraph("This is the fourth paragraph, in a new section."); document.InsertSectionPageBreak(); // document.PageLayout.Orientation = Orientation.Portrait; var sections = document.GetSections(); // Add a paragraph to display the result of sections. var p = document.InsertParagraph("This document contains ").Append(sections.Count.ToString()).Append(" Sections.\n"); p.SpacingBefore(40d); // Display the paragraphs count per section from this document. for (int i = 0; i < sections.Count; ++i) { var section = sections[i]; var paragraphs = section.SectionParagraphs; var nonEmptyParagraphs = paragraphs.Where(x => !string.IsNullOrEmpty(x.Text)); p.Append("Section ").Append((i + 1).ToString()).Append(" has ").Append(nonEmptyParagraphs.Count().ToString()).Append(" non-empty paragraphs.\n"); } document.Save(); Console.WriteLine("\tCreated: InsertSections.docx\n"); } }
public override IEnumerable <TemplMatchSection> FindAll(DocX doc, TemplRegex rxp) { // Expecting only 1 match per section return(TemplMatchSection.Find(rxp, doc.GetSections(), 1)); }