1- // Load the existing Word document
2- using Syncfusion . DocIO . DLS ;
1+ using Syncfusion . DocIO . DLS ;
32using Syncfusion . DocIO ;
43using Syncfusion . Drawing ;
54
6- using ( FileStream inputStream = new FileStream ( Path . GetFullPath ( "Data/Input .docx" ) , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
5+ using ( FileStream inputStream = new FileStream ( Path . GetFullPath ( "Data/Template .docx" ) , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
76{
8- // Open the input Word document
9- WordDocument document = new WordDocument ( inputStream , FormatType . Docx ) ;
10- // Iterate through all the styles in the document
11- foreach ( Style style in document . Styles )
7+ // Open the input Word document.
8+ using ( WordDocument document = new WordDocument ( inputStream , FormatType . Docx ) )
129 {
13- // Check if the style is a Paragraph style
14- if ( style . StyleType == StyleType . ParagraphStyle )
10+ // Iterate through all the styles in the document
11+ foreach ( Style style in document . Styles )
1512 {
16- // Cast the style to WParagraphStyle and modify the text color
17- WParagraphStyle paraStyle = style as WParagraphStyle ;
18- if ( paraStyle != null )
13+ // Check if the style is a Paragraph style.
14+ if ( style . StyleType == StyleType . ParagraphStyle )
1915 {
20- paraStyle . CharacterFormat . TextColor = Color . Purple ;
16+ // Cast the style to WParagraphStyle and modify the text color.
17+ WParagraphStyle paraStyle = style as WParagraphStyle ;
18+ if ( paraStyle != null )
19+ paraStyle . CharacterFormat . TextColor = Color . Purple ;
2120 }
22- }
23- // Check if the style is a Character style
24- else if ( style . StyleType == StyleType . CharacterStyle )
25- {
26- // Cast the style to WCharacterStyle and modify the text color
27- WCharacterStyle charStyle = style as WCharacterStyle ;
28- if ( charStyle != null )
21+ // Check if the style is a Character style.
22+ else if ( style . StyleType == StyleType . CharacterStyle )
2923 {
30- charStyle . CharacterFormat . TextColor = Color . Red ;
24+ // Cast the style to WCharacterStyle and modify the text color.
25+ WCharacterStyle charStyle = style as WCharacterStyle ;
26+ if ( charStyle != null )
27+ charStyle . CharacterFormat . TextColor = Color . Red ;
3128 }
3229 }
33- }
34- // Save the modified document
35- using ( FileStream outputStream = new FileStream ( Path . GetFullPath ( "Output/Result.docx" ) , FileMode . Create , FileAccess . Write ) )
36- {
37- document . Save ( outputStream , FormatType . Docx ) ;
30+ // Save the modified document.
31+ using ( FileStream outputStream = new FileStream ( Path . GetFullPath ( "Output/Result.docx" ) , FileMode . Create , FileAccess . Write ) )
32+ {
33+ document . Save ( outputStream , FormatType . Docx ) ;
34+ }
3835 }
3936}
0 commit comments