{"id":2378,"date":"2026-10-19T15:56:06","date_gmt":"2026-10-19T07:56:06","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2378"},"modified":"2026-03-29T10:04:29","modified_gmt":"2026-03-29T10:04:29","slug":"how-to-use-rangeclearhyperlinks-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeclearhyperlinks-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.ClearHyperlinks in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>ClearHyperlinks<\/code> member of the <code>Range<\/code> object in the Excel object model is a method used to remove all hyperlinks from a specified range of cells. When working with Excel files via xlwings in Python, this functionality is particularly useful for cleaning up data, preparing ranges for new hyperlinks, or simply removing unwanted links that may interfere with data processing or presentation. It operates by clearing the hyperlink formatting and the underlying link address, leaving the cell&#8217;s display text (if any) intact as plain text.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, the <code>ClearHyperlinks<\/code> method is accessed through a <code>Range<\/code> object. The syntax is straightforward, as it does not require any parameters. The general format is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range_object.clear_hyperlinks()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>range_object<\/code> is an instance of <code>xlwings.Range<\/code>, representing the cell or range of cells from which hyperlinks are to be removed. The method applies to all cells within that range, and if no hyperlinks are present, it has no effect.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Consider an Excel workbook where a worksheet contains various hyperlinks in cells A1 through A10, linking to external websites or internal documents. To remove all these hyperlinks using xlwings, you can execute the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Open the workbook and specify the worksheet\nwb = xw.Book('example.xlsx')\nsheet = wb.sheets&#91;'Sheet1']\n\n# Define the range containing hyperlinks\ntarget_range = sheet.range('A1:A10')\n\n# Remove all hyperlinks from the range\ntarget_range.clear_hyperlinks()\n\n# Save and close the workbook (optional)\nwb.save()\nwb.close()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `ClearHyperlinks` member of the `Range` object in the Excel object model is a method used to rem&#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-2378","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2378","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=2378"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2378\/revisions"}],"predecessor-version":[{"id":3622,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2378\/revisions\/3622"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}