{"id":2073,"date":"2026-05-20T07:37:00","date_gmt":"2026-05-19T23:37:00","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2073"},"modified":"2026-03-28T06:09:16","modified_gmt":"2026-03-28T06:09:16","slug":"how-to-use-applicationdefaultsaveformat-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationdefaultsaveformat-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.DefaultSaveFormat in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Application.DefaultSaveFormat property in Excel&#8217;s object model is a read\/write property that determines the default file format used when saving a new workbook. This property influences the file format (e.g., .xlsx, .xls, .csv) that Excel will default to in the &#8220;Save As&#8221; dialog for a new, unsaved workbook. It does not change the format of already saved workbooks. In xlwings, this property is accessed via the Application object, allowing automation scripts to programmatically set or retrieve the default save format, ensuring consistency in file operations across automated Excel processes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The property is accessed through the <code>app<\/code> object (an instance of xlwings&#8217; App). The syntax is straightforward, as it maps directly to the Excel object model:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To get the current default save format:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>default_format = app.api.DefaultSaveFormat<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To set a new default save format:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.DefaultSaveFormat = format_value<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>app<\/code> refers to the xlwings App instance (e.g., <code>app = xw.App()<\/code> or <code>xw.apps.active<\/code>). The <code>format_value<\/code> is an integer corresponding to the Excel file format constant. xlwings uses the Excel object model&#8217;s constants, which can be referenced via the <code>app.api<\/code> interface. Common values include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>51<\/code>: xlOpenXMLWorkbook (.xlsx, without macros)<\/li>\n\n\n\n<li><code>52<\/code>: xlOpenXMLWorkbookMacroEnabled (.xlsm, with macros)<\/li>\n\n\n\n<li><code>50<\/code>: xlExcel12 (Excel Binary Workbook .xlsb)<\/li>\n\n\n\n<li><code>6<\/code>: xlCSV (CSV format)<\/li>\n\n\n\n<li><code>-4143<\/code>: xlWorkbookNormal (legacy .xls format in older Excel versions)<br>These constants are part of the Excel enumeration <code>XlFileFormat<\/code>. In xlwings, you can use the integer values directly or, for clarity, define them as variables (e.g., <code>xlOpenXMLWorkbook = 51<\/code>). Note that the property is specific to the Excel application instance, so changes apply to all workbooks under that instance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Examples:<\/strong><br>Below are practical xlwings API code examples demonstrating how to use the DefaultSaveFormat property.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Retrieving the Current Default Save Format:<\/strong><br>This example connects to the active Excel instance and prints the current default save format.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel application\napp = xw.apps.active\n\n# Get the default save format\ncurrent_format = app.api.DefaultSaveFormat\nprint(f\"Current default save format value: {current_format}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output might show an integer like <code>51<\/code>, indicating .xlsx is the default.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Setting the Default Save Format to .xlsm:<\/strong><br>This example sets the default save format to Excel Macro-Enabled Workbook (.xlsm) for new workbooks.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Start a new Excel instance (or use active)\napp = xw.App(visible=False) # Run in background\n\n# Define the format value for .xlsm\nxlOpenXMLWorkbookMacroEnabled = 52\n\n# Set the default save format\napp.api.DefaultSaveFormat = xlOpenXMLWorkbookMacroEnabled\n\n# Verify the change\nprint(f\"Default save format set to: {app.api.DefaultSaveFormat}\")\n\n# Clean up: close the app without saving\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After running this, any new workbook created in this Excel instance will default to .xlsm when saved for the first time.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Using DefaultSaveFormat in a Workflow:<\/strong><br>This example integrates DefaultSaveFormat into a script that creates a workbook and saves it, leveraging the default format.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Launch Excel and set default to CSV for data export tasks\napp = xw.App(visible=True)\napp.api.DefaultSaveFormat = 6 # xlCSV\n\n# Add a new workbook\nwb = app.books.add()\nsheet = wb.sheets&#91;0]\nsheet.range('A1').value = &#91;&#91;'Data', 'Value'], &#91;1, 100], &#91;2, 200]]\n\n# Save the workbook; it will default to CSV in the Save As dialog\n# Note: This property doesn't auto-save; it sets the dialog default.\nwb.save('new_data') # User may see .csv as default in the dialog\n\n# Close\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Application.DefaultSaveFormat property in Excel&apos;s object model is a read\/write property that det&#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-2073","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2073","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=2073"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2073\/revisions"}],"predecessor-version":[{"id":3172,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2073\/revisions\/3172"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}