Skip to content

Commit fe9f063

Browse files
Added sample
1 parent 122d5fe commit fe9f063

5 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.37216.2 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply_Characterformat_for_Hyperlink", "Apply_Characterformat_for_Hyperlink\Apply_Characterformat_for_Hyperlink.csproj", "{61A4F7A7-571E-2042-E82C-0B351C92C7E4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{61A4F7A7-571E-2042-E82C-0B351C92C7E4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3F08D4D1-1A99-462D-9B46-44C9EE3AAA13}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Output\.gitkeep">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.Drawing;
4+
5+
namespace Apply_Characterformat_for_Hyperlink
6+
{
7+
class Program
8+
{
9+
10+
static void Main(string[] args)
11+
{
12+
//Creates a new Word document
13+
using (WordDocument document = new WordDocument())
14+
{
15+
//Adds one section and one paragraph to the document
16+
document.EnsureMinimal();
17+
// Appends a hyperlink to the last paragraph of the document
18+
string linkUri = "https://www.syncfusion.com";
19+
IWField field = document.LastParagraph.AppendHyperlink(linkUri, "Syncfusion", HyperlinkType.WebLink);
20+
// Character format for hyperlink
21+
bool isItalic = false;
22+
bool isUnderline = true;
23+
bool isStrikeout = false;
24+
bool isBold = false;
25+
float fontSize = 12;
26+
//Format hyperlink
27+
IEntity entity = field;
28+
//Iterates to sibling items until Field End
29+
while (entity.NextSibling != null)
30+
{
31+
if (entity is WTextRange)
32+
{
33+
WTextRange textRange = entity as WTextRange;
34+
//Apply character format for text ranges
35+
textRange.CharacterFormat.FontName = "Verdana";
36+
textRange.CharacterFormat.FontSize = fontSize;
37+
textRange.CharacterFormat.TextColor = Color.Red;
38+
textRange.CharacterFormat.Bold = isBold;
39+
textRange.CharacterFormat.Italic = isItalic;
40+
textRange.CharacterFormat.UnderlineStyle = isUnderline ? UnderlineStyle.Single : UnderlineStyle.None;
41+
textRange.CharacterFormat.Strikeout = isStrikeout;
42+
}
43+
else if ((entity is WFieldMark) && (entity as WFieldMark).Type == FieldMarkType.FieldEnd)
44+
break;
45+
//Gets next sibling item.
46+
entity = entity.NextSibling;
47+
}
48+
49+
//Saves the Word document to the file stream.
50+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
51+
{
52+
document.Save(outputStream, FormatType.Docx);
53+
}
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)