{"id":2339,"date":"2026-09-30T07:28:40","date_gmt":"2026-09-29T23:28:40","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2339"},"modified":"2026-03-29T09:34:46","modified_gmt":"2026-03-29T09:34:46","slug":"how-to-use-worksheetprotectdrawingobjects-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetprotectdrawingobjects-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.ProtectDrawingObjects in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>ProtectDrawingObjects<\/strong> property of a <strong>Worksheet<\/strong> object in Excel is a Boolean value that indicates whether the shapes (drawing objects) on the worksheet are protected. When a worksheet is protected using the <code>Protect<\/code> method, this property can be set to <code>True<\/code> to prevent users from modifying, moving, or deleting shapes such as charts, text boxes, and other drawing objects. It is particularly useful when you want to lock down the visual elements of a worksheet while still allowing data entry in cells, depending on the overall protection settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, you can access this property through the <code>api<\/code> property of a Worksheet object, which provides direct access to the underlying Excel object model. The property is read\/write, meaning you can both retrieve its current value and set it to a new value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>worksheet.api.ProtectDrawingObjects<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>worksheet<\/strong>: An xlwings Worksheet object representing the target worksheet.<\/li>\n\n\n\n<li><strong>ProtectDrawingObjects<\/strong>: Returns or sets a Boolean value (<code>True<\/code> or <code>False<\/code>).<\/li>\n\n\n\n<li><code>True<\/code>: Drawing objects are protected (locked) when the worksheet is protected.<\/li>\n\n\n\n<li><code>False<\/code>: Drawing objects are not protected, even if the worksheet is protected.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Note that this property only takes effect when the worksheet is protected. If the worksheet is not protected, drawing objects remain editable regardless of this setting. To protect the worksheet, use the <code>Protect<\/code> method, such as <code>worksheet.api.Protect()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Code:<\/strong><br>Here is a practical example demonstrating how to use the <strong>ProtectDrawingObjects<\/strong> property with xlwings. This example assumes you have an Excel workbook open and a worksheet named &#8220;Sheet1&#8221;. It checks the current protection status for drawing objects, sets it to <code>True<\/code>, protects the worksheet, and then verifies the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel application and workbook\napp = xw.apps.active\nwb = app.books.active\nws = wb.sheets&#91;'Sheet1']\n\n# Check the current ProtectDrawingObjects setting\ncurrent_setting = ws.api.ProtectDrawingObjects\nprint(f\"Current ProtectDrawingObjects setting: {current_setting}\")\n\n# Set ProtectDrawingObjects to True to protect shapes when the sheet is protected\nws.api.ProtectDrawingObjects = True\n\n# Protect the worksheet to activate the drawing object protection\n# You can specify a password and other options; here, we use default settings\nws.api.Protect(Password=None, DrawingObjects=True, Contents=True, Scenarios=True)\n# Note: The 'DrawingObjects' parameter in the Protect method corresponds to ProtectDrawingObjects.\n\n# Verify the protection status\nif ws.api.ProtectDrawingObjects:\n    print(\"Drawing objects are now protected on this worksheet.\")\nelse:\n    print(\"Drawing objects are not protected.\")\n\n# Optionally, unprotect the worksheet to make changes\nws.api.Unprotect()\nws.api.ProtectDrawingObjects = False\nprint(\"Worksheet unprotected and ProtectDrawingObjects set to False.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **ProtectDrawingObjects** property of a **Worksheet** object in Excel is a Boolean value that in&#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-2339","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2339","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=2339"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2339\/revisions"}],"predecessor-version":[{"id":3567,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2339\/revisions\/3567"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}