{"id":2384,"date":"2026-10-22T16:55:55","date_gmt":"2026-10-22T08:55:55","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2384"},"modified":"2026-03-29T10:07:43","modified_gmt":"2026-03-29T10:07:43","slug":"how-to-use-rangecopy-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangecopy-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.Copy in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Copy<\/code> method in Excel&#8217;s Range object is a fundamental operation for duplicating cell contents, formatting, and formulas to another location within the same workbook or to a different workbook. In xlwings, this functionality is accessed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model. This allows for precise control over the copy operation, including specifying a destination range.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality<\/strong><br>The primary purpose of the <code>Copy<\/code> method is to replicate a source range. It copies all elements: values, formulas, number formats, cell formatting (like borders and fill), and column widths\/row heights if the entire column\/row is selected. This is equivalent to performing a standard copy-paste operation in the Excel UI. The method can be used without a destination to copy to the Clipboard, or with a destination to paste directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax<\/strong><br>The xlwings API call follows the pattern of the Excel VBA <code>Range.Copy<\/code> method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range_object.api.Copy(Destination)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>range_object<\/code><\/strong>: Your xlwings Range object (e.g., <code>sheet.range('A1:B2')<\/code>).<\/li>\n\n\n\n<li><strong><code>.api<\/code><\/strong>: The gateway to the native Excel object model.<\/li>\n\n\n\n<li><strong><code>.Copy<\/code><\/strong>: The method itself.<\/li>\n\n\n\n<li><strong><code>Destination<\/code><\/strong> (Optional): An xlwings Range object specifying the top-left cell of the destination range. If omitted, the range is copied to the Clipboard.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameter Details<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Parameter<\/th><th class=\"has-text-align-left\" data-align=\"left\">Type<\/th><th class=\"has-text-align-left\" data-align=\"left\">Description<\/th><th class=\"has-text-align-left\" data-align=\"left\">Required<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>Destination<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">xlwings Range Object<\/td><td class=\"has-text-align-left\" data-align=\"left\">The target cell where the copied range will be pasted. Only the top-left cell needs to be specified; the paste area will match the size of the source range.<\/td><td class=\"has-text-align-left\" data-align=\"left\">No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Copy to a specific destination (direct paste):<\/strong><br>This is the most common use case. It copies <code>A1:D5<\/code> from <code>Sheet1<\/code> and pastes it starting at cell <code>F1<\/code> on the same sheet.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book.active\nsht = wb.sheets&#91;'Sheet1']\nsource_range = sht.range('A1:D5')\ndestination_cell = sht.range('F1')\nsource_range.api.Copy(Destination=destination_cell.api)<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Copy to the Clipboard:<\/strong><br>By not providing a <code>Destination<\/code> argument, the range is placed on the Windows\/macOS Clipboard. Another application (like another Excel instance or Notepad) can then paste it.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nsht = xw.Book.active.sheets&#91;0]\nsht.range('A1:A10').api.Copy() # Data is now on the clipboard<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Copy between different worksheets:<\/strong><br>This example copies data from <code>Sheet1<\/code> to <code>Sheet2<\/code>, starting at cell <code>A1<\/code> on the target sheet.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book.active\nsource_sht = wb.sheets&#91;'Sheet1']\ntarget_sht = wb.sheets&#91;'Sheet2']\nsource_sht.range('C10:F20').api.Copy(Destination=target_sht.range('A1').api)<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Copy using a Range object variable for the destination:<\/strong><br>This demonstrates using a pre-defined Range object as the target, which can be useful in dynamic scripts.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.open('report.xlsx')\nsource = wb.sheets&#91;'Data'].range('Table1&#91;#All]') # Copy an entire Table\ntarget_start = wb.sheets&#91;'Summary'].range('B5')\nsource.api.Copy(Destination=target_start.api)\nwb.save()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Copy` method in Excel&apos;s Range object is a fundamental operation for duplicating cell contents, &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2384","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2384","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=2384"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2384\/revisions"}],"predecessor-version":[{"id":3630,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2384\/revisions\/3630"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}