DOCX
Links
External hyperlinks, bookmarks, and cross-references in Word documents
Add navigation to your documents with hyperlinks and bookmarks.
External Hyperlinks
Link to external URLs:
import { Paragraph, ExternalHyperlink, TextRun } from "@office-open/docx";
new Paragraph({
children: [
new ExternalHyperlink({
link: "https://example.com",
children: [
new TextRun({
text: "Visit example.com",
underline: { type: "single" },
color: "0563C1",
}),
],
}),
],
});
Internal Hyperlinks
Link to bookmarks within the same document:
import { Paragraph, ExternalHyperlink, TextRun } from "@office-open/docx";
new Paragraph({
children: [
new ExternalHyperlink({
link: "https://example.com",
anchor: "section-intro",
children: [new TextRun({ text: "Go to Introduction", color: "0563C1" })],
}),
],
});
Bookmarks
Define bookmarks that can be linked to:
import { Paragraph, Bookmark, TextRun } from "@office-open/docx";
new Paragraph({
children: [new Bookmark({ id: "section-intro" }), new TextRun("Introduction")],
});
Use bookmarks with internal hyperlinks for cross-referencing within a document. The anchor property of ExternalHyperlink can reference bookmark IDs.
Screen Tips
Add a tooltip that appears on hover:
new ExternalHyperlink({
link: "https://example.com",
tooltip: "Click to visit Example",
children: [new TextRun({ text: "Example Link", color: "0563C1" })],
});