{"id":2310,"date":"2026-09-15T15:46:50","date_gmt":"2026-09-15T07:46:50","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2310"},"modified":"2026-03-28T12:50:26","modified_gmt":"2026-03-28T12:50:26","slug":"how-to-use-worksheetcommentsthreaded-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetcommentsthreaded-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.CommentsThreaded in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Worksheet object&#8217;s <code>CommentsThreaded<\/code> property in xlwings provides access to the collection of threaded comments associated with a specific worksheet. Threaded comments, introduced in newer versions of Microsoft Excel, allow for modern, conversation-style discussions attached to a cell, differing from the older single &#8220;Comment&#8221; (now often called a &#8220;Note&#8221;). This property is essential for programmatically managing these collaborative discussions, enabling developers to read, add, reply to, or delete comment threads directly from Python, thereby automating feedback collection, review processes, or annotation systems within workbooks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Key Members<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The property is accessed via <code>Worksheet.comments_threaded<\/code>. It returns a <code>CommentsThreaded<\/code> collection object. The primary method for adding a new threaded comment is <code>add<\/code>. The key syntax in xlwings is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_comment = ws.comments_threaded.add(cell, text, author=None)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>cell<\/code> (required):<\/strong> An xlwings <code>Range<\/code> object or a string address (e.g., <code>\"A1\"<\/code>) specifying the cell to which the comment thread will be attached.<\/li>\n\n\n\n<li><strong><code>text<\/code> (required):<\/strong> A string containing the content of the initial comment in the thread.<\/li>\n\n\n\n<li><strong><code>author<\/code> (optional):<\/strong> A string specifying the author&#8217;s name for the comment. If omitted, it typically defaults to a system or application-defined name.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>add<\/code> method returns a <code>CommentThreaded<\/code> object, which itself has useful properties and methods, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.text<\/code>: Gets or sets the text of the specific comment (if accessed from a reply within the thread, careful indexing of the <code>.comments<\/code> collection is needed).<\/li>\n\n\n\n<li><code>.replies<\/code>: A collection of replies within the thread. You can use <code>.replies.add(text)<\/code> to post a new reply.<\/li>\n\n\n\n<li><code>.delete()<\/code>: Deletes the entire comment thread.<\/li>\n<\/ul>\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>Adding a New Threaded Comment:<\/strong><br>This example adds a new threaded comment to cell B5.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book(\"example.xlsx\")\nws = wb.sheets&#91;\"Sheet1\"]\nnew_thread = ws.comments_threaded.add(\"B5\", \"Initial review: Please verify these figures.\", author=\"AnalysisBot\")\nwb.save()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Reading Existing Threaded Comments:<\/strong><br>This loop iterates through all threaded comments on the sheet and prints their location and the text of the first comment in each thread.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book(\"example.xlsx\")\nws = wb.sheets&#91;\"Sheet1\"]\nfor comment_thread in ws.comments_threaded:\n    # The CommentThreaded object's .cell property gives its location\n    print(f\"Cell {comment_thread.cell.address}: {comment_thread.text}\")<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Replying to a Comment Thread:<\/strong><br>This example finds a comment thread in cell D10 and adds a reply to it.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book(\"example.xlsx\")\nws = wb.sheets&#91;\"Sheet1\"]\n# Assuming a thread exists in D10. In practice, you might loop to find it.\nfor thread in ws.comments_threaded:\n    if thread.cell.address == \"$D$10\":\n        thread.replies.add(\"Reply: Figures have been updated and confirmed.\", author=\"ReviewerJane\")\n        break\nwb.save()<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Deleting a Specific Comment Thread:<\/strong><br>This deletes the threaded comment located at cell F7.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book(\"example.xlsx\")\nws = wb.sheets&#91;\"Sheet1\"]\nfor thread in ws.comments_threaded:\n    if thread.cell.address == \"$F$7\":\n        thread.delete()\n        break\nwb.save()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Worksheet object&apos;s `CommentsThreaded` property in xlwings provides access to the collection of t&#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-2310","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2310","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=2310"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2310\/revisions"}],"predecessor-version":[{"id":3523,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2310\/revisions\/3523"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}