{"id":2304,"date":"2026-09-12T16:35:52","date_gmt":"2026-09-12T08:35:52","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2304"},"modified":"2026-03-28T12:44:00","modified_gmt":"2026-03-28T12:44:00","slug":"how-to-use-worksheetautofiltermode-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetautofiltermode-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.AutoFilterMode in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>AutoFilterMode<\/code> property of a <code>Worksheet<\/code> object in Excel is a read-write Boolean attribute that indicates whether the AutoFilter drop-down arrows are currently displayed on the worksheet. This property is particularly useful for programmatically controlling the visibility of AutoFilter UI elements without directly interacting with the filter criteria. In xlwings, you can access this property through the <code>api<\/code> property of a <code>Worksheet<\/code> object, which provides direct access to the underlying Excel object model.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When <code>AutoFilterMode<\/code> is set to <code>True<\/code>, the AutoFilter drop-down arrows appear in the header row of a filtered range (if one exists), allowing users to interactively filter data.<\/li>\n\n\n\n<li>When set to <code>False<\/code>, the arrows are hidden, but any existing filter settings remain intact. This means data may still be filtered, but the UI for adjusting filters is not visible.<\/li>\n\n\n\n<li>It is important to note that <code>AutoFilterMode<\/code> does not actually apply or remove filters; it only toggles the display of the AutoFilter interface. To manage filter criteria, use methods like <code>AutoFilter<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The property is accessed via the <code>api<\/code> interface of a <code>Worksheet<\/code> object. The general syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>worksheet.api.AutoFilterMode<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns a Boolean value (<code>True<\/code> or <code>False<\/code>). To set the property, assign a Boolean value directly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>worksheet.api.AutoFilterMode = True # Shows AutoFilter arrows\nworksheet.api.AutoFilterMode = False # Hides AutoFilter arrows<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No parameters are required for this property, as it is a simple attribute.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Below are practical xlwings code examples that demonstrate how to use <code>AutoFilterMode<\/code> in different scenarios.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Checking AutoFilter Visibility:<\/strong><br>This example checks if AutoFilter arrows are displayed on a worksheet and prints the status.<\/li>\n<\/ol>\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# Check the current AutoFilterMode status\nif ws.api.AutoFilterMode:\n    print(\"AutoFilter arrows are visible.\")\nelse:\n    print(\"AutoFilter arrows are hidden.\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Toggling AutoFilter Display:<\/strong><br>This example toggles the visibility of AutoFilter arrows based on their current state.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book('example.xlsx')\nws = wb.sheets&#91;'Sheet1']\n\n# Toggle the AutoFilterMode\nws.api.AutoFilterMode = not ws.api.AutoFilterMode\nprint(f\"AutoFilterMode is now set to: {ws.api.AutoFilterMode}\")<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Ensuring AutoFilter Arrows Are Hidden:<\/strong><br>This example hides the AutoFilter arrows without affecting any active filters, useful for cleaning up the UI before sharing the workbook.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book('example.xlsx')\nws = wb.sheets&#91;'Sheet1']\n\n# Hide AutoFilter arrows if they are visible\nif ws.api.AutoFilterMode:\n    ws.api.AutoFilterMode = False\n    print(\"AutoFilter arrows have been hidden.\")\nelse:\n    print(\"AutoFilter arrows were already hidden.\")<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Combining with AutoFilter Application:<\/strong><br>This example applies an AutoFilter to a range and then ensures the arrows are visible. It demonstrates how <code>AutoFilterMode<\/code> interacts with actual filtering.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book('example.xlsx')\nws = wb.sheets&#91;'Sheet1']\n\n# Apply AutoFilter to range A1:C10 (assuming headers are in row 1)\nws.range('A1:C10').api.AutoFilter(Field=1, Criteria1=\">100\") # Filter column A for values > 100\n\n# Make sure AutoFilter arrows are displayed\nws.api.AutoFilterMode = True\nprint(\"AutoFilter applied and arrows are visible.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `AutoFilterMode` property of a `Worksheet` object in Excel is a read-write Boolean attribute tha&#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-2304","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2304","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=2304"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2304\/revisions"}],"predecessor-version":[{"id":3513,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2304\/revisions\/3513"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}