{"id":44,"date":"2026-02-06T11:08:15","date_gmt":"2026-02-06T03:08:15","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=44"},"modified":"2026-01-17T05:27:59","modified_gmt":"2026-01-17T05:27:59","slug":"how-to-insert-cell-comments-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-insert-cell-comments-using-xlwings\/","title":{"rendered":"How To Insert Cell Comments Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.api.Range(&#8216;A3&#8242;).AddComment(Text=&#8217;Cell comments&#8217;)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Check if cell A3 has a comment<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">if sht.api.Range(&#8216;A3&#8217;).Comment is None:<\/p>\n<p style=\"margin: 0in; margin-left: .375in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"en-US\">p<\/span><span lang=\"zh-CN\">rint(&#8216;Cell A3 has no comment.&#8217;)<\/span><\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">else:<\/p>\n<p style=\"margin: 0in; margin-left: .375in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"en-US\">p<\/span><span lang=\"zh-CN\">rint(&#8216;Cell A3 has a comment.&#8217;)<\/span><\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Hide a comment in cell A3<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.api.Range(&#8216;A3&#8217;).Comment.Visible=False<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Delete a comment in cell A3<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.api.Range(&#8216;A3&#8217;).Comment.Delete()<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Cell comments\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.active    #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\n#xlwings API\nsht.api.Range('A3').AddComment(Text='Cell comments')\n\n#Check if cell A3 has a comment\nif sht.api.Range('A3').Comment is None:\n    print('Cell A3 has no comment.')\nelse:\n    print('Cell A3 has a comment.')\n\n#Hide a comment in cell A3\nsht.api.Range('A3').Comment.Visible=False\n\n#Delete a comment in cell A3\nsht.api.Range('A3').Comment.Delete()\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/44","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=44"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}