コード例 #1
0
ファイル: Paragraph.cs プロジェクト: shestakov/wordroller
        public void InsertSectionBreak(SectionBreakType breakType)
        {
            var xName = XName.Get("sectPr", Namespaces.w.NamespaceName);

            var pPr = Xml.Element(XName.Get("pPr", Namespaces.w.NamespaceName));

            if (pPr?.Element(xName) != null)
            {
                throw new InvalidOperationException("Paragraph already defines a section");
            }

            pPr = ((IParagraphPropertiesContainer)this).GetOrCreateParagraphPropertiesXmlElement();
            var sectPr = new XElement(xName);

            if (breakType != SectionBreakType.NextPage)
            {
                sectPr.SetAttributeValue(Namespaces.w + "type", breakType.ToCamelCase());
            }

            pPr.Add(sectPr);
        }
コード例 #2
0
        /// <summary>
        /// Starting a new Document Section after the last paragraph in the Document Body. Document Body must contain at least one paragraph.
        /// </summary>
        public void StartNewSection(SectionBreakType?sectionBreakType = null)
        {
            var lastParagraph = Paragraphs.LastOrDefault() ??
                                throw new InvalidOperationException("Body must contain at least one paragraph to start a new section");

            var sectPr = new XElement(LastSectionProperties.Xml);

            lastParagraph.Properties.SetSectionProperties(sectPr);

            LastSectionProperties.Xml.SetSingleElementAttributeOrRemoveElement("type", "val", sectionBreakType?.ToCamelCase());
        }