{"id":2427,"date":"2026-11-13T07:28:04","date_gmt":"2026-11-12T23:28:04","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2427"},"modified":"2026-03-29T10:39:46","modified_gmt":"2026-03-29T10:39:46","slug":"how-to-use-rangeshowcard-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeshowcard-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.ShowCard in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>ShowCard<\/code> member of the <code>Range<\/code> object in the Excel object model is accessible through the <code>xlwings<\/code> API, enabling the display of a specific card from the Office Fluent UI, such as a contextual tooltip or a mini-toolbar, for a selected cell or range. This functionality is primarily used to enhance user interaction by programmatically triggering UI elements that are typically shown in response to user actions, like hovering over a cell with specific content. It can be useful in automated workflows where guiding the user&#8217;s attention to certain options or information is required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, the <code>ShowCard<\/code> method is called on a <code>Range<\/code> object. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range_object.api.ShowCard(cardID)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>range_object<\/code>: This is an xlwings <code>Range<\/code> object, representing the cell or range in Excel where the card should be displayed.<\/li>\n\n\n\n<li><code>cardID<\/code>: A required parameter of type <code>Integer<\/code> or <code>Variant<\/code>. It specifies the identifier of the card to show. The cardID corresponds to specific UI elements in Excel, and its values are not explicitly documented in public Excel object model references. Typically, these IDs are internal constants used by Excel, and discovering the correct ID for a particular card may require experimentation or referencing internal Excel resources. For example, common cards might include formatting options or comment indicators, but exact IDs are not standardized in the xlwings documentation.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Here is a code example demonstrating how to use the <code>ShowCard<\/code> member with xlwings. This example assumes you have an Excel workbook open and a specific range selected, and it attempts to show a card (note that the exact cardID may need adjustment based on your Excel version and configuration):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance and workbook\napp = xw.apps.active\nwb = app.books.active\n\n# Define a range, e.g., cell A1 on the active sheet\ntarget_range = wb.sheets.active.range('A1')\n\n# Call the ShowCard method with a hypothetical cardID (e.g., 1)\n# In practice, you need to determine the correct cardID for your needs\ntry:\n    target_range.api.ShowCard(1)\n    print(\"Card shown for range A1.\")\nexcept Exception as e:\n    print(f\"Error showing card: {e}\")\n\n# Alternatively, you can use it on a larger range, like B2:D5\nanother_range = wb.sheets.active.range('B2:D5')\ntry:\n    another_range.api.ShowCard(2) # Using a different cardID\n    print(\"Card shown for range B2:D5.\")\nexcept Exception as e:\n    print(f\"Error showing card: {e}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `ShowCard` member of the `Range` object in the Excel object model is accessible through the `xlw&#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-2427","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2427","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=2427"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2427\/revisions"}],"predecessor-version":[{"id":3686,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2427\/revisions\/3686"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}