{"id":2080,"date":"2026-05-23T15:36:35","date_gmt":"2026-05-23T07:36:35","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2080"},"modified":"2026-03-28T06:13:50","modified_gmt":"2026-03-28T06:13:50","slug":"how-to-use-applicationdisplaycommentindicator-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationdisplaycommentindicator-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.DisplayCommentIndicator in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>DisplayCommentIndicator<\/code> property in the Excel Application object determines how cell comments (also known as notes) are visually indicated within a worksheet. This setting is crucial for controlling the visibility of comment indicators, which are the small red triangles typically found in the top-right corner of cells containing comments. By adjusting this property, users can tailor the display to suit different workflows, such as hiding indicators for a cleaner view or showing them only when comments are present. This property is particularly useful in collaborative environments where comment tracking is essential, or when preparing reports where visual clutter should be minimized.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, the <code>DisplayCommentIndicator<\/code> property can be accessed through the <code>Application<\/code> object. The syntax for using this property is straightforward: <code>app.display_comment_indicator<\/code>. Here, <code>app<\/code> refers to an instance of the xlwings <code>App<\/code> class, which represents the Excel application. The property accepts integer values that correspond to specific display modes, as defined in Excel&#8217;s object model. The possible values and their meanings are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-1<\/code>: Displays comment indicators only when comments are present (default). This is the standard setting where red triangles appear in cells with comments.<\/li>\n\n\n\n<li><code>0<\/code>: Hides comment indicators entirely. In this mode, no visual cues are shown, even if cells contain comments, which can make the worksheet look cleaner but may hide important annotations.<\/li>\n\n\n\n<li><code>1<\/code>: Always shows comment indicators, regardless of whether comments are present. This mode is less common but can be used for consistency in certain templates or to highlight cells intended for comments.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To set or retrieve the <code>DisplayCommentIndicator<\/code> property in xlwings, you first need to establish a connection to the Excel application. For example, you can use <code>xlwings.App()<\/code> to launch a new instance or connect to an existing one. Once the application object is available, you can directly assign or read the property value. This property is application-wide, meaning it affects all open workbooks and worksheets in that Excel instance. It is important to note that changes made via xlwings are immediately reflected in the Excel interface, allowing for dynamic adjustments during automation scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some practical xlwings API code examples demonstrating the use of the <code>DisplayCommentIndicator<\/code> property:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Retrieving the current display setting<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=True) # Start or connect to Excel\ncurrent_setting = app.display_comment_indicator\nprint(f\"Current DisplayCommentIndicator setting: {current_setting}\")\n# This will output -1, 0, or 1 based on the current configuration.\napp.quit() # Close the application<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Hiding comment indicators for a cleaner view<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=True)\napp.display_comment_indicator = 0 # Hide indicators\nprint(\"Comment indicators are now hidden.\")\n# You can open a workbook here to see the effect, e.g., app.books.open('example.xlsx')\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Showing indicators only when comments exist (default reset)<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False) # Run in background\napp.display_comment_indicator = -1 # Set to default\nprint(\"DisplayCommentIndicator reset to default (show only with comments).\")\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Always displaying comment indicators for consistency<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwith xw.App(visible=True) as app: # Using context manager for automatic cleanup\napp.display_comment_indicator = 1 # Always show indicators\nwb = app.books.open('sample.xlsx')\n# The workbook will now show red triangles in all cells, even empty ones.\nwb.save()\n# The setting persists until changed or Excel is restarted.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `DisplayCommentIndicator` property in the Excel Application object determines how cell comments &#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-2080","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2080","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=2080"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2080\/revisions"}],"predecessor-version":[{"id":3183,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2080\/revisions\/3183"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}