Skip to content

Commit cc6c5d6

Browse files
committed
Added changes
1 parent e27981f commit cc6c5d6

1 file changed

Lines changed: 47 additions & 36 deletions

File tree

  • Paragraphs/Create_clickable_highlighted_text/.NET/Create-clickable-highlighted-text
Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
11
using Syncfusion.DocIO;
22
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.Drawing;
34

4-
namespace Create_list_with_hanging_indent
5+
WordDocument document = new WordDocument();
6+
IWSection section = document.AddSection();
7+
8+
// Paragraph containing highlighted hyperlink word
9+
IWParagraph para = section.AddParagraph();
10+
11+
para.AppendText("For detailed information, refer to ");
12+
13+
IWField hyperlink = para.AppendHyperlink(
14+
"Section5", // Bookmark name
15+
"Section 5", // Display text
16+
HyperlinkType.Bookmark);
17+
18+
19+
WTextRange textRange = hyperlink.OwnerParagraph.ChildEntities[
20+
hyperlink.OwnerParagraph.ChildEntities.Count - 2] as WTextRange;
21+
22+
if (textRange != null)
23+
{
24+
textRange.CharacterFormat.HighlightColor = Color.Yellow;
25+
}
26+
27+
para.AppendText(" in this document.");
28+
29+
//Add some content before destination
30+
for (int i = 0; i < 5; i++)
531
{
6-
internal class Program
7-
{
8-
static void Main(string[] args)
9-
{
10-
// Create a new Word document.
11-
using (WordDocument document = new WordDocument())
12-
{
13-
// Add a section to the document.
14-
IWSection section = document.AddSection();
15-
16-
// Add a bulleted list item with a hanging indent.
17-
IWParagraph bulletParagraph1 = section.AddParagraph();
18-
bulletParagraph1.ListFormat.ApplyDefBulletStyle();
19-
bulletParagraph1.AppendText("First").CharacterFormat.FontSize = 12;
20-
bulletParagraph1.ParagraphFormat.FirstLineIndent = -18; // Hanging indent for bullet alignment.
21-
22-
// Add a normal paragraph with a first-line indent.
23-
IWParagraph normalParagraph = section.AddParagraph();
24-
normalParagraph.AppendText("Sample text with first-line indent.").CharacterFormat.FontSize = 12;
25-
normalParagraph.ParagraphFormat.FirstLineIndent = 35;
26-
27-
// Add another bulleted list item with a hanging indent.
28-
IWParagraph bulletParagraph2 = section.AddParagraph();
29-
bulletParagraph2.ListFormat.ApplyDefBulletStyle();
30-
bulletParagraph2.AppendText("Second").CharacterFormat.FontSize = 12;
31-
bulletParagraph2.ParagraphFormat.FirstLineIndent = -18; // Hanging indent for bullet alignment.
32-
33-
// Save the document.
34-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write))
35-
{
36-
document.Save(outputFileStream, FormatType.Docx);
37-
}
38-
}
39-
}
40-
}
32+
para = section.AddParagraph();
33+
para.AppendBookmarkStart($"Section{i}");
34+
para.AppendText($"Sample paragraph {i + 1}");
35+
para.AppendBookmarkEnd($"Section{i}");
4136
}
37+
38+
// Bookmark destination
39+
IWParagraph destinationPara = section.AddParagraph();
40+
41+
//Bookmark start
42+
destinationPara.AppendBookmarkStart("Section5");
43+
44+
//Destination content
45+
destinationPara.AppendText("Section 5 - Detailed Information");
46+
47+
//Bookmark end
48+
destinationPara.AppendBookmarkEnd("Section5");
49+
section.AddParagraph().AppendText("End");
50+
//Save document
51+
document.Save(@"../../../Output/Output.docx", FormatType.Docx);
52+
document.Close();

0 commit comments

Comments
 (0)