{"id":46,"date":"2026-02-07T11:37:52","date_gmt":"2026-02-07T03:37:52","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=46"},"modified":"2026-01-17T05:30:59","modified_gmt":"2026-01-17T05:30:59","slug":"how-to-set-cell-alignment-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-cell-alignment-using-xlwings\/","title":{"rendered":"How To Set Cell Alignment Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>#Setting the alignments of cell C3<\/p>\n<p>sht.api.Range(&#8216;C3&#8217;).HorizontalAlignment = xw.constants.Constants.xlCenter\u00a0<\/p>\n<p>#sht.api.Range(&#8216;C3&#8217;).VerticalAlignment = xw.constants.Constants.xlCenter<\/p>\n<p>sht.api.Range(&#8216;C3&#8242;).Value=&#8217;Test1&#8217;<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Cell Alignment\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#Setting the alignments of cell C3\nsht.api.Range('C3').HorizontalAlignment = xw.constants.Constants.xlCenter  \nsht.api.Range('C3').VerticalAlignment = xw.constants.Constants.xlCenter\nsht.api.Range('C3').Value='Test1'\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\/40.png\" alt=\"Set Cell Alignment Using xlwings\" class=\"wp-image-325\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/40.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/40-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/40-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-46","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/46","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=46"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/46\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}