{"id":30,"date":"2026-02-01T18:00:37","date_gmt":"2026-02-01T10:00:37","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=30"},"modified":"2026-01-16T06:57:31","modified_gmt":"2026-01-16T06:57:31","slug":"how-to-copy-cell-ranges-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-copy-cell-ranges-using-openpyxl.html","title":{"rendered":"How To Copy Cell Ranges Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Copying content:<\/p>\n<p>from openpyxl.worksheet.cell_range import CellRange<\/p>\n<p>cr=CellRange(&#8216;D5:F7&#8217;)<\/p>\n<p>cr2=CellRange(&#8216;D12:F14&#8217;)<\/p>\n<p>r=cr2.max_row-cr.max_row<\/p>\n<p>c=cr2.max_col-cr.max_col<\/p>\n<p>for cl in cr.cells:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 cl2=ws.cell(row=cl[0],column=cl[1])<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 ws.cell(row=cl[0]+r,column=cl[1]+c,value=cl2.value)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Copy 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#Import CellRange class\nfrom openpyxl.worksheet.cell_range import CellRange\n\n#Create a cell range object\ncr=CellRange('D5:F7')\ncr2=CellRange('D12:F14')\n\n#Copy the values\nr=cr2.max_row-cr.max_row\nc=cr2.max_col-cr.max_col\nfor cl in cr.cells:\n      cl2=ws.cell(row=cl&#91;0],column=cl&#91;1])\n      ws.cell(row=cl&#91;0]+r,column=cl&#91;1]+c,value=cl2.value)\n\nwb.save('test.xlsx')\nwb.close()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\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-30","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/30","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=30"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":264,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions\/264"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}