{"id":2138,"date":"2026-06-21T16:18:08","date_gmt":"2026-06-21T08:18:08","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2138"},"modified":"2026-03-28T07:58:04","modified_gmt":"2026-03-28T07:58:04","slug":"how-to-use-applicationmappapersize-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationmappapersize-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.MapPaperSize in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>MapPaperSize<\/code> member of the <code>Application<\/code> object in Excel is a property that enables developers to control whether Excel automatically scales printed output to fit the paper size defined by the printer driver. This is particularly useful when dealing with documents that may be printed on different printers with varying default paper sizes, such as switching between A4 and Letter formats. By setting this property, you can ensure consistent print scaling behavior, preventing unexpected layout changes or scaling issues when printing across diverse systems or regional settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function is to manage automatic paper size mapping. When enabled, Excel attempts to match the paper size in the document&#8217;s page setup with a similar size available in the current printer&#8217;s driver. If a direct match isn&#8217;t found, Excel may scale the printout. Disabling this property turns off automatic scaling, which can be beneficial when you require exact, unscaled printing, ensuring the output strictly adheres to the specified page dimensions regardless of the printer&#8217;s default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, you access this property through the <code>Application<\/code> object. The property is a Boolean value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app = xw.apps.active # Or xw.App() for a new instance\napp.api.MapPaperSize<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Get the current value:<\/strong> <code>current_setting = app.api.MapPaperSize<\/code><\/li>\n\n\n\n<li><strong>Set the value:<\/strong> <code>app.api.MapPaperSize = True<\/code> or <code>app.api.MapPaperSize = False<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters:<\/strong><br>The property accepts a Boolean:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>True<\/code>: Enables automatic paper size mapping (this is the default in Excel). Excel will adjust scaling to fit the printer&#8217;s paper.<\/li>\n\n\n\n<li><code>False<\/code>: Disables automatic mapping. Excel prints without scaling adjustment, using the exact paper size from the page setup.<\/li>\n<\/ul>\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>Check the current setting:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.apps.active\nif app.api.MapPaperSize:\n    print(\"Automatic paper size mapping is ON.\")\nelse:\n    print(\"Automatic paper size mapping is OFF.\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Disable automatic paper size mapping for precise printing:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book(r'C:\\Reports\\Q1_Summary.xlsx')\napp = wb.app\napp.api.MapPaperSize = False # Turn off auto-scaling\nwb.save()\nprint(\"MapPaperSize disabled to ensure exact print dimensions.\")<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Temporarily change setting, print, then restore:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.apps.active\noriginal_setting = app.api.MapPaperSize # Store original state\ntry:\n    app.api.MapPaperSize = True # Enable mapping for flexible printing\n    app.api.ActiveSheet.PrintOut() # Print the active sheet\nfinally:\n    app.api.MapPaperSize = original_setting # Restore original setting\n    print(\"Print job completed with temporary MapPaperSize adjustment.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `MapPaperSize` member of the `Application` object in Excel is a property that enables developers&#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-2138","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2138","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=2138"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2138\/revisions"}],"predecessor-version":[{"id":3269,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2138\/revisions\/3269"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}