{"id":37,"date":"2026-02-02T18:41:12","date_gmt":"2026-02-02T10:41:12","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=37"},"modified":"2026-01-17T05:07:04","modified_gmt":"2026-01-17T05:07:04","slug":"how-to-reference-the-last-row-or-column-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-reference-the-last-row-or-column-using-xlwings\/","title":{"rendered":"How To Reference the Last Row or Column Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Last row<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"zh-CN\">sht.range(&#8216;A1&#8217;).end(&#8216;down&#8217;).<\/span><span lang=\"en-US\">select()<\/span><\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.range(&#8216;A1&#8217;).end(&#8216;down&#8217;).row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.cells(1,1).end(&#8216;down&#8217;).row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.range(&#8216;A&#8217;+str(sht.api.Rows.Count)).end(&#8216;up&#8217;).row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.cells(sht.api.Rows.Count,1).end(&#8216;up&#8217;).row<\/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;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Range(&#8216;A1&#8217;).End(xw.constants.Direction.xlDown).Row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Cells(1,1).End(xw.constants.Direction.xlDown).Row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Range(&#8216;A&#8217;+str(sht.api.Rows.Count)).End(xw.constants.Direction.xlUp).Row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Cells(sht.api.Rows.Count,1).End(xw.constants.Direction.xlUp).Row<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<h3 style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Last column<\/span><\/h3>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.range(&#8216;A1&#8217;).end(&#8216;right&#8217;).column<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.cells(1,1).end(&#8216;right&#8217;).column<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.cells(1,sht.api.Columns.Count).end(&#8216;left&#8217;).column<\/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;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Range(&#8216;A1&#8217;).End(xw.constants.Direction.xlToRight).Column<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Cells(1,1).End(xw.constants.Direction.xlToRight).Column<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.api.Cells(1,sht.api.Columns.Count).End(xw.constants.Direction.xlToLeft).Column<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Referencing the Last Row or Column\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.open('last.xlsx')    #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\n#Last row\n#xlwings\nsht.range('A1').end('down').select()\nprint(sht.range('A1').end('down').row)\n#sht.cells(1,1).end('down').row\n#sht.range('A'+str(sht.api.Rows.Count)).end('up').row\n#sht.cells(sht.api.Rows.Count,1).end('up').row\n\n#xlwings API\n#sht.api.Range('A1').End(xw.constants.Direction.xlDown).Row\n#sht.api.Cells(1,1).End(xw.constants.Direction.xlDown).Row\n#sht.api.Range('A'+str(sht.api.Rows.Count)).End(xw.constants.Direction.xlUp).Row\n#sht.api.Cells(sht.api.Rows.Count,1).End(xw.constants.Direction.xlUp).Row\n\n#Last column\n#xlwings\n#sht.range('A1').end('right').column\n#sht.cells(1,1).end('right').column\n#sht.cells(1,sht.api.Columns.Count).end('left').column\n\n#xlwings API\n#sht.api.Range('A1').End(xw.constants.Direction.xlToRight).Column\n#sht.api.Cells(1,1).End(xw.constants.Direction.xlToRight).Column\n#sht.api.Cells(1,sht.api.Columns.Count).End(xw.constants.Direction.xlToLeft).Column\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\/22.png\" alt=\"Reference the Last Row or Column Using xlwings\" class=\"wp-image-292\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/22.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/22-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/22-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"764\" height=\"236\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/23.png\" alt=\"\" class=\"wp-image-293\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/23.png 764w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/23-300x93.png 300w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/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-37","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/37","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=37"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}