Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
}
Loading