diff --git a/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink.sln b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink.sln new file mode 100644 index 00000000..d6cc1229 --- /dev/null +++ b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37216.2 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply_Characterformat_for_Hyperlink", "Apply_Characterformat_for_Hyperlink\Apply_Characterformat_for_Hyperlink.csproj", "{61A4F7A7-571E-2042-E82C-0B351C92C7E4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3F08D4D1-1A99-462D-9B46-44C9EE3AAA13} + EndGlobalSection +EndGlobal diff --git a/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Apply_Characterformat_for_Hyperlink.csproj b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Apply_Characterformat_for_Hyperlink.csproj new file mode 100644 index 00000000..38b8e1e0 --- /dev/null +++ b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Apply_Characterformat_for_Hyperlink.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + + diff --git a/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/Result.docx b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/Result.docx new file mode 100644 index 00000000..a461b893 Binary files /dev/null and b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/Result.docx differ diff --git a/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/gitkeep.txt b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/gitkeep.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Output/gitkeep.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Program.cs b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Program.cs new file mode 100644 index 00000000..af52d51d --- /dev/null +++ b/Fields/Apply_Characterformat_for_Hyperlink/.NET/Apply_Characterformat_for_Hyperlink/Program.cs @@ -0,0 +1,57 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Drawing; + +namespace Apply_Characterformat_for_Hyperlink +{ + class Program + { + + static void Main(string[] args) + { + //Creates a new Word document + using (WordDocument document = new WordDocument()) + { + //Adds one section and one paragraph to the document + document.EnsureMinimal(); + // Appends a hyperlink to the last paragraph of the document + string linkUri = "https://www.syncfusion.com"; + IWField field = document.LastParagraph.AppendHyperlink(linkUri, "Syncfusion", HyperlinkType.WebLink); + // Character format for hyperlink + bool isItalic = false; + bool isUnderline = true; + bool isStrikeout = false; + bool isBold = false; + float fontSize = 12; + //Format hyperlink + IEntity entity = field; + //Iterates to sibling items until Field End + while (entity.NextSibling != null) + { + if (entity is WTextRange) + { + WTextRange textRange = entity as WTextRange; + //Apply character format for text ranges + textRange.CharacterFormat.FontName = "Verdana"; + textRange.CharacterFormat.FontSize = fontSize; + textRange.CharacterFormat.TextColor = Color.Red; + textRange.CharacterFormat.Bold = isBold; + textRange.CharacterFormat.Italic = isItalic; + textRange.CharacterFormat.UnderlineStyle = isUnderline ? UnderlineStyle.Single : UnderlineStyle.None; + textRange.CharacterFormat.Strikeout = isStrikeout; + } + else if ((entity is WFieldMark) && (entity as WFieldMark).Type == FieldMarkType.FieldEnd) + break; + //Gets next sibling item. + entity = entity.NextSibling; + } + + //Saves the Word document to the file stream. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + document.Save(outputStream, FormatType.Docx); + } + } + } + } +}