{"id":2321,"date":"2026-09-21T07:58:59","date_gmt":"2026-09-20T23:58:59","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2321"},"modified":"2026-03-28T13:03:57","modified_gmt":"2026-03-28T13:03:57","slug":"how-to-use-worksheetenableoutlining-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetenableoutlining-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.EnableOutlining in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>EnableOutlining Property in xlwings<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Excel&#8217;s object model, the <code>EnableOutlining<\/code> property of a <code>Worksheet<\/code> object controls whether outlining (grouping and ungrouping of rows or columns) is allowed on the worksheet. When set to <code>True<\/code>, users can manually create and manipulate outlines via the Excel interface, such as grouping rows to collapse detail data and show summary rows. When set to <code>False<\/code>, outlining is disabled, preventing users from creating new groups or modifying existing ones. This property is useful for protecting the structure of a worksheet when distributing workbooks, ensuring that predefined outline levels remain intact.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, the <code>EnableOutlining<\/code> property is accessed through the <code>api<\/code> property of a <code>Sheet<\/code> object (which corresponds to a <code>Worksheet<\/code> in Excel&#8217;s object model). The property is a boolean value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sheet.api.EnableOutlining = True # Enable outlining\nsheet.api.EnableOutlining = False # Disable outlining<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>sheet<\/strong>: An xlwings <code>Sheet<\/code> object representing the worksheet.<\/li>\n\n\n\n<li><strong>.api<\/strong>: Provides direct access to the underlying Excel object model (via pywin32 on Windows or appscript on macOS).<\/li>\n\n\n\n<li><strong>EnableOutlining<\/strong>: The property name as defined in the Excel object model. It can be set to <code>True<\/code> or <code>False<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters and Usage<\/strong><br>The property does not take additional parameters. It simply gets or sets a boolean value. Note that enabling or disabling outlining does not affect existing outlines; it only controls whether new outlines can be created or existing ones modified by the user. In Excel, this setting is often used in combination with worksheet protection (<code>Protect<\/code> method) to lock the outline structure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Enabling Outlining on a Worksheet<\/strong><br>This example opens an Excel workbook, enables outlining on the first sheet, and saves the file. Users will then be able to group rows or columns manually in Excel.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Open an existing workbook or create a new one\napp = xw.App(visible=False)\nworkbook = app.books.open('example.xlsx')\nsheet = workbook.sheets&#91;0]\n\n# Enable outlining\nsheet.api.EnableOutlining = True\n\n# Save and close\nworkbook.save()\nworkbook.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Disabling Outlining and Protecting the Worksheet<\/strong><br>Here, outlining is disabled, and the worksheet is protected to prevent any changes to the outline structure. This is common in finalized reports.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.App(visible=False)\nworkbook = app.books.open('report.xlsx')\nsheet = workbook.sheets&#91;'Summary']\n\n# Disable outlining to lock grouping features\nsheet.api.EnableOutlining = False\n\n# Protect the worksheet (optional: add a password)\nsheet.api.Protect(Password=\"your_password\", AllowFormattingCells=True)\n\nworkbook.save('report_locked.xlsx')\nworkbook.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Checking the Current Outlining Status<\/strong><br>You can also retrieve the current value of <code>EnableOutlining<\/code> to conditionally modify the worksheet.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.App(visible=False)\nworkbook = app.books.open('data.xlsx')\nsheet = workbook.sheets&#91;0]\n\n# Get the current outlining status\nis_outlining_enabled = sheet.api.EnableOutlining\nprint(f\"Outlining is enabled: {is_outlining_enabled}\")\n\n# If disabled, enable it\nif not is_outlining_enabled:\n    sheet.api.EnableOutlining = True\n    workbook.save()\n\nworkbook.close()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>**EnableOutlining Property in xlwings**<\/p>\n<p>In Excel&apos;s object model, the `EnableOutlining` property of &#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-2321","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2321","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=2321"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2321\/revisions"}],"predecessor-version":[{"id":3538,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2321\/revisions\/3538"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}