File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments