Skip to content

Commit 33be179

Browse files
Modified sample
1 parent 2ec024f commit 33be179

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Program.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ static void Main(string[] args)
1616

1717
//Set style properties
1818
customStyle.CharacterFormat.FontName = "Calibri";
19-
customStyle.CharacterFormat.FontSize = 18;
20-
customStyle.CharacterFormat.Bold = true;
19+
customStyle.CharacterFormat.FontSize = 22;
2120
customStyle.CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Single;
22-
//Get text range
23-
WTextRange textRange = null;
24-
if (wordDocument.LastParagraph.ChildEntities.Count > 0)
25-
textRange = wordDocument.LastParagraph.ChildEntities[0] as WTextRange;
26-
//Apply custom style
27-
if (textRange != null)
28-
textRange.ApplyStyle("MyCustomStyle");
21+
22+
// Find the first occurrence of the target text
23+
TextSelection selection = document.Find("Adventure Works Cycles", true,true);
24+
25+
if (selection != null)
26+
{
27+
// Convert selection into a single text range and apply the style.
28+
WTextRange textRange = selection.GetAsOneRange();
29+
textRange.ApplyStyle("MyCustomStyle");
30+
}
2931
//Creates file stream.
3032
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
3133
{

0 commit comments

Comments
 (0)