{"id":20,"date":"2026-01-27T18:52:49","date_gmt":"2026-01-27T10:52:49","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=20"},"modified":"2026-01-16T06:26:46","modified_gmt":"2026-01-16T06:26:46","slug":"how-to-used-cell-range-of-a-worksheet-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-used-cell-range-of-a-worksheet-using-openpyxl.html","title":{"rendered":"How To Used Cell Range of a Worksheet Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>When the first N rows or columns of data are empty, there may be issues when iterating over all rows using the `rows` property of the worksheet object or over all columns using the `columns` property.<\/p>\n<p>Use the following properties of the worksheet object to construct a `CellRange` object:<\/p>\n<p>&gt;&gt;&gt; from openpyxl.worksheet.cell_range import CellRange<\/p>\n<p>&gt;&gt;&gt; cr=CellRange(min_col=ws.min_column,max_col=ws.max_column,\u00a0 \u00a0min_row=ws.min_row,max_row=ws.max_row)<\/p>\n<p>&gt;&gt;&gt; cr.coord<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Used Range of Cells in a Worksheet\n\n#Import load_workbook function\nfrom openpyxl import Workbook\n\n#Create a new workbook\nwb=Workbook()\n#Get the active worksheet\nws=wb.active\n\n#Import the CellRange function\nfrom openpyxl.worksheet.cell_range import CellRange\n\n#Use the CellRange function to create a cell range object\ncr=CellRange(min_col=ws.min_column,max_col=ws.max_column, \\\n             min_row=ws.min_row,max_row=ws.max_row)\n\n#Output the coordinates of the cell range\nprint(cr.coord)\n\nwb.save('test.xlsx')\nwb.close()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>OpenPyXL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":235,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/235"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}