{"id":19,"date":"2026-01-27T11:03:01","date_gmt":"2026-01-27T03:03:01","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=19"},"modified":"2026-01-16T06:24:47","modified_gmt":"2026-01-16T06:24:47","slug":"how-to-reference-a-cell-range-using-openpyxl-2","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-reference-a-cell-range-using-openpyxl-2.html","title":{"rendered":"How To Reference a Cell Range Using OpenPyXL? (2)"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Using the `CellRange` class.<\/p>\n<p>from openpyxl.worksheet.cell_range import CellRange<\/p>\n<h3>Attributes of CellRange Object<\/h3>\n<ul>\n<li>bottom,top,left,right\u00a0 &#8211; Coordinates of the four sides of the range.<\/li>\n<li>cells, cols, rows &#8211; Cell coordinates.<\/li>\n<li>bounds &#8211; Vertices, similar to `(8, 3, 10, 5)`.<\/li>\n<li>min_row, min_col, max_row, max_col &#8211; Row or column numbers around the range.<\/li>\n<li>size &#8211; Size<\/li>\n<\/ul>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Referencing Cell Ranges\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#Use the `CellRange` method to create a cell range object\nfrom openpyxl.worksheet import cell_range as cr\ncr0=cr.CellRange(min_row=2,max_row=5,min_col=3,max_col=6)\n\n#Coordinates of cells in the bottom row of the range\nprint(cr0.bottom)\n\n#Coordinates of cells in the top row of the range\nprint(cr0.top)\n\n#Coordinates of cells in the leftmost column of the range\nprint(cr0.left)\n\n#Coordinates of cells in the rightmost column of the range\nprint(cr0.right)\n\n#Minimum row number in the range\nprint(cr0.min_row)\n\n#Minimum column number in the range\nprint(cr0.min_col)\n\n#Maximum row number in the range\nprint(cr0.max_row)\n\n#Maximum column number in the range\nprint(cr0.max_col)\n\n#Size of the range\nprint(cr0.size)\n\n#Coordinates of the top-left and\n#bottom-right cells of the range\nprint(cr0.bounds)\n\n#Coordinates of the top-left and\n#bottom-right cells of the range\nprint(cr0.coord)\n\n#Coordinates of each row's cells in the range\nfor cell in cr0.rows:\n    print(cell)\n\n#Coordinates of each column's cells in the range\nfor cell in cr0.cols:\n    print(cell)\n\n#Coordinates of each individual cell in the range\nfor cell in cr0.cells:\n    print(cell)\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-19","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/19","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=19"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}