public static Style GetParagraphStyle(this ParagraphProperties pPr, WordprocessingDocument document) { if (document == null) { throw new ArgumentNullException("document"); } return(document.GetParagraphStyle(pPr.GetParagraphStyleId())); }
public static Style GetParagraphStyle(this Paragraph paragraph, WordprocessingDocument document) { if (paragraph == null) { throw new ArgumentNullException("paragraph"); } if (document == null) { throw new ArgumentNullException("document"); } return(document.GetParagraphStyle(paragraph.GetParagraphStyleId())); }
/// <summary> /// Creates a new paragraph style with the specified style ID, primary /// style name, and aliases and add it to the specified style definitions /// part. Saves the data in the DOM tree back to the part. /// </summary> /// <param name="document">The document</param> /// <param name="styleId">The style's unique ID</param> /// <param name="styleName">The style's name</param> /// <param name="basedOn">The base style</param> /// <param name="nextStyle">The next paragraph's style</param> /// <returns>The newly created style</returns> public static Style CreateParagraphStyle(this WordprocessingDocument document, string styleId, string styleName, string basedOn, string nextStyle) { // Check parameters if (document == null) { throw new ArgumentNullException("document"); } if (styleId == null) { throw new ArgumentNullException("styleId"); } if (styleName == null) { throw new ArgumentNullException("styleName"); } if (basedOn == null) { throw new ArgumentNullException("basedOn"); } if (nextStyle == null) { throw new ArgumentNullException("nextStyle"); } // Check whether the style already exists. var style = document.GetParagraphStyle(styleId); if (style != null) { throw new ArgumentException("Style '" + styleId + "' already exists!", styleId); } // Create a new paragraph style element and specify key attributes. style = new Style { Type = StyleValues.Paragraph, CustomStyle = true, StyleId = styleId }; // Add key child elements style.Produce <StyleName>().Val = styleName; style.Produce <BasedOn>().Val = basedOn; style.Produce <NextParagraphStyle>().Val = nextStyle; // Add the style to the styles part return(document.ProduceStylesElement().AppendChild(style)); }
public static int GetOutlineLevel(this Paragraph paragraph, WordprocessingDocument document) { if (paragraph == null) { throw new ArgumentNullException("paragraph"); } if (document == null) { throw new ArgumentNullException("document"); } var style = document.GetParagraphStyle(paragraph.GetParagraphStyleId()); if (style != null && style.StyleParagraphProperties != null && style.StyleParagraphProperties.OutlineLevel != null) { return(style.StyleParagraphProperties.OutlineLevel.Val + 1); } return(StyleExtensions.BodyTextOutlineLevel); }