public static CharacterPropertiesBase NewParagraphStyle(this Document document, int paragraph, bool doNotApply = false) { var documentParagraph = document.Paragraphs[paragraph]; document.InsertText(documentParagraph.Range.Start, $"test{paragraph}"); var documentStyle = new DocumentStyle() { StyleName = $"{PsStyleName}{paragraph}", FontSize = 22, FontName = "Verdana" }; var paragraphStyle = documentStyle.Get(document); if (!doNotApply) { documentParagraph.Style = (ParagraphStyle)paragraphStyle; } return(paragraphStyle); }
static IEnumerable <CharacterStyle> NewCharacterStyle(this Document document, int stylesCount, bool doNotApply) { for (int i = 0; i < stylesCount; i++) { var documentRange = document.AppendText($"test{i}"); var documentStyle = new DocumentStyle() { StyleName = $"{CsStyleName}{i}", FontSize = 22, FontName = "Verdana", DocumentStyleType = DocumentStyleType.Character }; var charPropsStyle = (CharacterStyle)documentStyle.Get(document); document.CharacterStyles.Add(charPropsStyle); if (!doNotApply) { var charProps = document.BeginUpdateCharacters(documentRange); charProps.Style = charPropsStyle; document.EndUpdateCharacters(charProps); } yield return(charPropsStyle); } }