{"id":2088,"date":"2026-05-27T15:30:45","date_gmt":"2026-05-27T07:30:45","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2088"},"modified":"2026-03-28T06:20:27","modified_gmt":"2026-03-28T06:20:27","slug":"how-to-use-applicationdisplayinsertoptions-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationdisplayinsertoptions-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.DisplayInsertOptions in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>DisplayInsertOptions<\/code> property of the <code>Application<\/code> object in Excel is a boolean setting that controls whether Excel displays the &#8220;Insert Options&#8221; button. This button appears when you insert cells, rows, or columns into a worksheet, offering a small drop-down menu with formatting choices (like &#8220;Format Same As Left&#8221; or &#8220;Clear Formatting&#8221;) to quickly adjust the formatting of the newly inserted cells. By default, this feature is enabled in Excel. Using the xlwings API, you can programmatically check the current state of this setting or turn it on or off, which can be useful for creating a cleaner user interface during automated processes or for ensuring consistent behavior in your macros.<\/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\">The property is accessed through the <code>app<\/code> object, which represents the Excel application.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.display_insert_options<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This property is both readable and writable. It expects a boolean value (<code>True<\/code> or <code>False<\/code>).<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Getting the current value:<\/strong> <code>current_state = app.display_insert_options<\/code><\/li>\n\n\n\n<li><strong>Setting the value:<\/strong> <code>app.display_insert_options = False<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters:<\/strong><br>The property itself does not take parameters. When setting it, you assign a boolean value directly.<\/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>Checking the Current Setting:<\/strong><br>This code checks if the Insert Options button is currently enabled and prints its status.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance\napp = xw.apps.active\n\n# Get the current state of DisplayInsertOptions\nis_enabled = app.display_insert_options\nprint(f\"The 'Insert Options' button is currently enabled: {is_enabled}\")\n\n# Optional: Close the connection\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Disabling the Insert Options Button:<\/strong><br>This script turns off the display of the Insert Options button. This is often done at the start of an automation script to prevent the button from appearing and potentially interfering with the visual flow of the macro.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Disable the Insert Options button\napp.display_insert_options = False\nprint(\"Insert Options button has been disabled.\")\n\n# ... Perform other tasks like inserting rows\/cells ...\n# Example: Insert a row at the top of the active sheet\napp.books.active.sheets.active.range('1:1').insert()\n\n# Remember to re-enable it if desired for the user later\n# app.display_insert_options = True<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Toggling the Setting Based on a Condition:<\/strong><br>This example shows a more practical use case where you might store the original setting, change it for your operations, and then restore it afterwards, ensuring the user&#8217;s preference is maintained.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\ndef run_clean_insertion():\napp = xw.apps.active\noriginal_setting = app.display_insert_options # Store original state\n\ntry:\n    app.display_insert_options = False # Turn off for our operations\n\n    # Perform a series of insertions without the button appearing\n    sheet = app.books.active.sheets.active\n    sheet.range('A5').insert('down') # Insert a cell, shifting down\n    sheet.range('C:C').insert() # Insert a column\n\nfinally:\n    app.display_insert_options = original_setting # Restore original state\n    print(f\"Insert Options setting restored to: {original_setting}\")\n\nif __name__ == '__main__':\n    run_clean_insertion()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `DisplayInsertOptions` property of the `Application` object in Excel is a boolean setting that c&#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-2088","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2088","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=2088"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2088\/revisions"}],"predecessor-version":[{"id":3196,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2088\/revisions\/3196"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}