---
title: "使用超链接"
---

Microsoft Word 文档中的超链接是 `HYPERLINK` 字段。在 Aspose.Words 中，超链接是通过 [FieldHyperlink](https://reference.aspose.com/words/python-net/aspose.words.fields/fieldhyperlink/) 类实现的。

## 插入超链接

使用 [insert_hyperlink](https://reference.aspose.com/words/python-net/aspose.words/documentbuilder/insert_hyperlink/) 方法将超链接插入到文档中。该方法接受三个参数：

1. 文档中显示的链接文本
2. 链接目的地（文档内的 URL 或书签名称）
3.布尔参数，如果`URL`是文档内书签的名称，则应为true

**InsertHyperlink** 方法始终在 URL 的开头和结尾添加撇号。

```

请注意，您需要使用 `Font` 属性显式指定超链接显示文本的字体格式。

```

以下代码示例演示如何使用 [DocumentBuilder](https://reference.aspose.com/words/python-net/aspose.words/documentbuilder/) 将超链接插入到文档中：

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Document-add_content_using_document_builder-InsertHyperlink.py" >}}

## 替换或修改超链接

Microsoft Word 文档中的超链接是一个字段。 Word文档中的字段是由多个节点组成的复杂结构，包括字段开始、字段代码、字段分隔符、字段结果和字段结束。字段可以嵌套、包含丰富的内容并跨越文档中的多个段落或部分。

要替换或修改超链接，需要在文档中查找超链接并替换其文本、URL 或两者。

以下代码示例演示如何查找Word文档中的所有超链接并更改其`URL`和显示名称：

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-working_with_fields-ReplaceHyperlinks.py" >}}
