diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph.sln b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph.sln new file mode 100644 index 00000000..b9876a27 --- /dev/null +++ b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36908.2 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply_Style_for_TextRange_in_Paragraph", "Apply_Style_for_TextRange_in_Paragraph\Apply_Style_for_TextRange_in_Paragraph.csproj", "{452CD0ED-C0B9-4470-B9E2-2BD0637A5DE9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {452CD0ED-C0B9-4470-B9E2-2BD0637A5DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {452CD0ED-C0B9-4470-B9E2-2BD0637A5DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {452CD0ED-C0B9-4470-B9E2-2BD0637A5DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {452CD0ED-C0B9-4470-B9E2-2BD0637A5DE9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {71836959-C790-4489-9E18-88A90C162AAA} + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Apply_Style_for_TextRange_in_Paragraph.csproj b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Apply_Style_for_TextRange_in_Paragraph.csproj new file mode 100644 index 00000000..b4a389b0 --- /dev/null +++ b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Apply_Style_for_TextRange_in_Paragraph.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + Always + + + Always + + + diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Data/Template.docx b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Data/Template.docx new file mode 100644 index 00000000..08423ebe Binary files /dev/null and b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Data/Template.docx differ diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/Result.docx b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/Result.docx new file mode 100644 index 00000000..85aa834a Binary files /dev/null and b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/Result.docx differ diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/gitkeep.txt b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/gitkeep.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Output/gitkeep.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Program.cs b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Program.cs new file mode 100644 index 00000000..a6284d64 --- /dev/null +++ b/Paragraphs/Apply_Style_for_TextRange_in_Paragraph/.NET/Apply_Style_for_TextRange_in_Paragraph/Program.cs @@ -0,0 +1,39 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +namespace Apply_Style_for_TextRange_in_Paragraph +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open)) + { + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, FormatType.Automatic)) + { + WCharacterStyle customStyle = wordDocument.AddCharacterStyle("MyCustomStyle") as WCharacterStyle; + + //Set style properties + customStyle.CharacterFormat.FontName = "Calibri"; + customStyle.CharacterFormat.FontSize = 18; + customStyle.CharacterFormat.Bold = true; + customStyle.CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Single; + //Get text range + WTextRange textRange = null; + if (wordDocument.LastParagraph.ChildEntities.Count > 0) + textRange = wordDocument.LastParagraph.ChildEntities[0] as WTextRange; + //Apply custom style + if (textRange != null) + textRange.ApplyStyle("MyCustomStyle"); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + wordDocument.Save(outputFileStream, FormatType.Docx); + } + } + } + } + } +} \ No newline at end of file