{"id":2063,"date":"2026-05-15T07:46:52","date_gmt":"2026-05-14T23:46:52","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2063"},"modified":"2026-03-28T06:00:14","modified_gmt":"2026-03-28T06:00:14","slug":"how-to-use-applicationcopyobjectswithcells-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcopyobjectswithcells-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.CopyObjectsWithCells in the xlwings API way"},"content":{"rendered":"\n<p><strong>Application.CopyObjectsWithCells Property in xlwings<\/strong><\/p>\n\n\n\n<p>The <code>Application.CopyObjectsWithCells<\/code> property in Excel, accessible via the xlwings API, controls whether drawing objects (such as shapes, charts, pictures, and other embedded objects) are copied or moved along with their associated cells during cut, copy, or fill operations in a worksheet. This property is a global application-level setting, meaning it affects the behavior across all open workbooks in the Excel instance controlled by xlwings. It is particularly useful for automating tasks where you need to ensure that graphical elements remain attached to specific data ranges when those ranges are manipulated.<\/p>\n\n\n\n<p><strong>Syntax and Parameters in xlwings<\/strong><\/p>\n\n\n\n<p>In xlwings, you interact with this property through the <code>app<\/code> object, which represents the Excel Application. The property is exposed as a read\/write Boolean attribute.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Property Access:<\/strong><\/li>\n\n\n\n<li><code>app.api.CopyObjectsWithCells<\/code> (using the <code>.api<\/code> attribute to access the underlying Excel object model directly).<\/li>\n\n\n\n<li>Alternatively, you can use <code>app.engine.api.CopyObjectsWithCells<\/code> if working with a specific engine context in more advanced scenarios, but typically the <code>app.api<\/code> route is standard.<\/li>\n\n\n\n<li><strong>Value:<\/strong><\/li>\n\n\n\n<li><strong><code>True<\/code><\/strong>: (Default) Drawing objects are copied, moved, or filled along with cells.<\/li>\n\n\n\n<li><strong><code>False<\/code><\/strong>: Drawing objects remain in their original positions on the worksheet; only the cell contents and formats are affected by the operation.<\/li>\n<\/ul>\n\n\n\n<p><strong>Code Examples<\/strong><\/p>\n\n\n\n<p>Here are practical xlwings code snippets demonstrating how to get and set this property, and its impact on operations.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Checking the Current Setting:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance or start a new one\napp = xw.apps.active\n\n# Get the current value of CopyObjectsWithCells\ncurrent_setting = app.api.CopyObjectsWithCells\nprint(f\"CopyObjectsWithCells is currently set to: {current_setting}\")\n# Output will be True or False<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Changing the Setting and Performing a Copy Operation:<\/strong><br>This example disables the copying of objects, copies a cell range, and then restores the original setting.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets&#91;0]\n\n# Assume cell A1 has a shape (e.g., a rectangle) over it and contains the number 10.\noriginal_setting = app.api.CopyObjectsWithCells\n\n# Set to False: Objects will NOT move with cells.\napp.api.CopyObjectsWithCells = False\nprint(\"Set CopyObjectsWithCells to False.\")\n\n# Copy cell A1 to B1. Only the value (10) will be copied.\nsheet.range('A1').copy(sheet.range('B1'))\n\n# Verify: B1 now contains 10, but the shape remains only over A1.\n\n# Restore the original application setting\napp.api.CopyObjectsWithCells = original_setting\nprint(\"Restored original setting.\")<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Automating a Task with Controlled Object Behavior:<\/strong><br>A more integrated example where you temporarily enable object copying to duplicate a data section with its associated chart.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\nwb = app.books&#91;'Report.xlsx']\ndata_sheet = wb.sheets&#91;'MonthlyData']\n\n# Ensure objects are copied with cells for this specific operation\napp.api.CopyObjectsWithCells = True\n\n# Define the source range (A1:D10) which includes data and an embedded chart object\nsource_range = data_sheet.range('A1:D10')\n# Define the target starting cell\ntarget_range = data_sheet.range('A12')\n\n# Copy the entire block, including the chart\nsource_range.copy(target_range)\n\n# Optional: Reset to default (True) or a previous state if needed for other macros\/users.\n# app.api.CopyObjectsWithCells = False<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>**Application.CopyObjectsWithCells Property in xlwings**<\/p>\n<p>The `Application.CopyObjectsWithCells` pro&#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-2063","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2063","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=2063"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2063\/revisions"}],"predecessor-version":[{"id":3157,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2063\/revisions\/3157"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}