{"id":2193,"date":"2026-07-19T07:09:37","date_gmt":"2026-07-18T23:09:37","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2193"},"modified":"2026-03-28T10:19:08","modified_gmt":"2026-03-28T10:19:08","slug":"how-to-use-applicationsmartartquickstyles-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationsmartartquickstyles-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.SmartArtQuickStyles in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The SmartArtQuickStyles member of the Application object in Excel refers to a collection that represents the set of SmartArt quick styles available within the application. In the context of xlwings, which provides a Pythonic interface to automate Excel, this collection can be accessed to retrieve information about or apply predefined style formats to SmartArt graphics in a workbook. This is particularly useful for programmatically enhancing the visual appeal of SmartArt diagrams, such as organizational charts or process flows, by applying consistent and professional styling without manual intervention.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function is to enumerate and possibly apply the quick styles to SmartArt objects. Each quick style in the collection defines a combination of fills, lines, and effects that can be applied to a SmartArt graphic to change its overall appearance. Through xlwings, you can access this collection to get the count of available styles or reference specific styles by their index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><br>In xlwings, the Application object is typically accessed via the <code>app<\/code> object when you have an instance of Excel running. The SmartArtQuickStyles collection is a property of the Application object. The syntax to access it is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.SmartArtQuickStyles<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns a SmartArtQuickStyles object, which is a collection. To interact with it, you can use methods and properties such as <code>Count<\/code> to get the number of styles, or <code>Item(index)<\/code> to retrieve a specific SmartArtQuickStyle object by its index (1-based). Note that xlwings uses the <code>.api<\/code> attribute to expose the underlying Excel object model, so this follows the standard Excel VBA object hierarchy but within Python.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>index<\/code>: An integer that specifies the position of the quick style in the collection. The index starts at 1. You can determine the total number of styles using the <code>Count<\/code> property.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><br>Below is an xlwings code example that demonstrates how to access the SmartArtQuickStyles collection and print the count of available styles. It also shows how to reference a specific style and apply it to an existing SmartArt graphic in the active workbook. This assumes you have an Excel instance running with a workbook open that contains at least one SmartArt graphic.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance\napp = xw.apps.active\n\n# Access the SmartArtQuickStyles collection\nquick_styles = app.api.SmartArtQuickStyles\n\n# Get the number of available quick styles\nstyle_count = quick_styles.Count\nprint(f\"Number of available SmartArt quick styles: {style_count}\")\n\n# Check if there are styles available\nif style_count > 0:\n    # Reference the first quick style in the collection (index 1)\n    first_style = quick_styles.Item(1)\n    print(f\"First quick style name: {first_style.Name}\")\n\n# Assume we have a SmartArt graphic in the active sheet\n# First, get the active sheet\nactive_sheet = app.api.ActiveSheet\n\n# Try to access the first SmartArt graphic in the sheet\n# Note: In practice, you need to ensure a SmartArt exists; this is simplified.\n# Typically, you might loop through shapes to find SmartArt.\n# Here, we assume the first shape is SmartArt for demonstration.\nshapes = active_sheet.Shapes\nif shapes.Count > 0:\n# Check if the shape is a SmartArt graphic (Type 24 represents SmartArt in Excel)\ntarget_shape = shapes.Item(1)\nif target_shape.Type == 24: # 24 is msoSmartArt, a constant for SmartArt\n    # Apply the first quick style to the SmartArt graphic\n    target_shape.SmartArt.QuickStyle = first_style\n    print(\"Applied the first quick style to the SmartArt graphic.\")\nelse:\n    print(\"The first shape is not a SmartArt graphic.\")\nelse:\n    print(\"No shapes found in the active sheet.\")\nelse:\n    print(\"No SmartArt quick styles are available.\")\n\n# Note: Error handling (e.g., for no SmartArt) should be added in production code.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SmartArtQuickStyles member of the Application object in Excel refers to a collection that repres&#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-2193","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2193","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=2193"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2193\/revisions"}],"predecessor-version":[{"id":3354,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2193\/revisions\/3354"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}