Skip to content

Commit 3e89c17

Browse files
Modified the Input document
1 parent 6f313de commit 3e89c17

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Paragraphs/Change-text-color-of-styles/Change-text-color-of-styles/Change-text-color-of-styles.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<None Update="Data\Input.docx">
1717
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1818
</None>
19+
<None Update="Data\Template.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
1922
<None Update="Output\.gitkeep">
2023
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2124
</None>
Binary file not shown.
Binary file not shown.
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
// Load the existing Word document
2-
using Syncfusion.DocIO.DLS;
1+
using Syncfusion.DocIO.DLS;
32
using Syncfusion.DocIO;
43
using 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

Comments
 (0)