{"id":2326,"date":"2026-09-23T16:37:02","date_gmt":"2026-09-23T08:37:02","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2326"},"modified":"2026-03-28T13:11:56","modified_gmt":"2026-03-28T13:11:56","slug":"how-to-use-worksheethyperlinks-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheethyperlinks-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.Hyperlinks in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Hyperlinks<\/code> member of the <code>Worksheet<\/code> object in the Excel object model provides access to a collection of all hyperlinks on a specific worksheet. Through xlwings, this collection can be manipulated to add, modify, or retrieve hyperlinks programmatically, enabling dynamic linking to web pages, documents, email addresses, or other cells within the workbook. This functionality is essential for creating interactive and navigable Excel reports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, the <code>Hyperlinks<\/code> collection is accessed via the <code>api<\/code> property of a worksheet object. The syntax is <code>ws.api.Hyperlinks<\/code>, where <code>ws<\/code> is an xlwings <code>Sheet<\/code> object representing the worksheet. The <code>Hyperlinks<\/code> collection has several key methods, most notably <code>Add<\/code>. The <code>Add<\/code> method creates a new hyperlink and has the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Anchor<\/code>: A required parameter specifying the range where the hyperlink will be placed. This is typically a <code>Range<\/code> object.<\/li>\n\n\n\n<li><code>Address<\/code>: The target address of the hyperlink (e.g., a URL like &#8220;https:\/\/www.example.com&#8221;).<\/li>\n\n\n\n<li><code>SubAddress<\/code>: An optional parameter for linking to a specific location within a file, such as a named range or a cell reference (e.g., &#8220;Sheet2!A1&#8221;).<\/li>\n\n\n\n<li><code>ScreenTip<\/code>: Optional text that appears when the user hovers over the hyperlink.<\/li>\n\n\n\n<li><code>TextToDisplay<\/code>: The optional visible text for the hyperlink. If omitted, the <code>Address<\/code> is displayed.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To retrieve an existing hyperlink, you can iterate through <code>ws.api.Hyperlinks<\/code> or access a specific one by index. Each hyperlink object in the collection has properties like <code>Address<\/code>, <code>SubAddress<\/code>, <code>ScreenTip<\/code>, and <code>Range<\/code>, which can be read or modified.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below are practical xlwings code examples demonstrating the use of the <code>Hyperlinks<\/code> member:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to an existing workbook and worksheet\nwb = xw.Book('example.xlsx')\nws = wb.sheets&#91;'Sheet1']\n\n# Example 1: Add a hyperlink to a website in cell A1\nlink_range = ws.range('A1')\nws.api.Hyperlinks.Add(Anchor=link_range.api,\nAddress='https:\/\/www.python.org',\nScreenTip='Visit Python Website',\nTextToDisplay='Python.org')\n\n# Example 2: Add a hyperlink to another cell in the same workbook\nws.api.Hyperlinks.Add(Anchor=ws.range('B2').api,\nAddress='',\nSubAddress='Sheet2!C5',\nTextToDisplay='Go to Sheet2')\n\n# Example 3: Loop through all hyperlinks on the worksheet and print their addresses\nfor link in ws.api.Hyperlinks:\n    print(f\"Hyperlink at {link.Range.Address}: {link.Address}\")\n\n# Example 4: Modify an existing hyperlink (e.g., the first one)\nif ws.api.Hyperlinks.Count > 0:\n    first_link = ws.api.Hyperlinks(1) # Index is 1-based\n    first_link.Address = 'https:\/\/www.xlwings.org'\n    first_link.TextToDisplay = 'xlwings Docs'\n\n# Save and close\nwb.save()\nwb.close()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Hyperlinks` member of the `Worksheet` object in the Excel object model provides access to a col&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2326","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2326"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2326\/revisions"}],"predecessor-version":[{"id":3545,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2326\/revisions\/3545"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}