{"id":48,"date":"2026-02-08T11:01:10","date_gmt":"2026-02-08T03:01:10","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=48"},"modified":"2026-01-17T05:34:26","modified_gmt":"2026-01-17T05:34:26","slug":"how-to-set-cell-borders-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-cell-borders-using-xlwings\/","title":{"rendered":"How To Set Cell Borders Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Border settings\u00a0<\/p>\n<p>`Index` can be one of the following `XlBordersIndex` constants: xlDiagonalDown\u3001xlDiagonalUp\u3001xlEdgeBottom\u3001xlEdgeLeft\u3001xlEdgeRight\u3001xlEdgeTop\u3001xlInsideHorizontal or xlInsideVertical\u3002<\/p>\n<p>\u00a0<\/p>\n<p>#xlwings API<\/p>\n<p>sht.api.Range(&#8216;B2&#8217;).CurrentRegion.Borders.LineStyle=xw.constants.LineStyle.xlContinuous<\/p>\n<p>#sht.api.Range(&#8216;B2&#8217;).CurrentRegion.Borders.ColorIndex=3<\/p>\n<p>#sht.api.Range(&#8216;B2&#8217;).CurrentRegion.Borders.Weight=xw.constants.BorderWeight.xlThick<\/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('B2').CurrentRegion.Borders.LineStyle=xw.constants.LineStyle.xlContinuous\nsht.api.Range('B2').CurrentRegion.Borders.ColorIndex=3\nsht.api.Range('B2').CurrentRegion.Borders.Weight=xw.constants.BorderWeight.xlThick\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/43.png\" alt=\"Set Cell Borders Using xlwings\" class=\"wp-image-331\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/43.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/43-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/43-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\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-48","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/48","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=48"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}