{"id":2396,"date":"2026-10-28T15:54:24","date_gmt":"2026-10-28T07:54:24","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2396"},"modified":"2026-03-29T10:16:24","modified_gmt":"2026-03-29T10:16:24","slug":"how-to-use-rangeexportasfixedformat-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeexportasfixedformat-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.ExportAsFixedFormat in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>ExportAsFixedFormat<\/code> member of the <code>Range<\/code> object in Excel&#8217;s object model is a powerful method for converting a specified range of cells into a fixed-layout format, most commonly a PDF or XPS file. This functionality is essential for generating reports, invoices, or any document that requires a precise, non-editable, and easily shareable format from an Excel worksheet. In xlwings, this method is accessed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model, allowing for precise control over the export process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax for calling <code>ExportAsFixedFormat<\/code> via xlwings is as follows:<br><code>range.api.ExportAsFixedFormat(Type, Filename, Quality, IncludeDocProperties, IgnorePrintAreas, From, To, OpenAfterPublish)<\/code><br>The parameters are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Type<\/code>: Required. Specifies the format type. Use <code>0<\/code> for PDF or <code>1<\/code> for XPS.<\/li>\n\n\n\n<li><code>Filename<\/code>: Optional. The full path and filename for the exported file. If omitted, Excel uses the workbook&#8217;s name and saves it in the current directory.<\/li>\n\n\n\n<li><code>Quality<\/code>: Optional. Can be <code>0<\/code> (Standard quality) or <code>1<\/code> (Minimum quality, smaller file size). Default is <code>0<\/code>.<\/li>\n\n\n\n<li><code>IncludeDocProperties<\/code>: Optional. <code>True<\/code> to include document properties in the file, <code>False<\/code> otherwise. Default is <code>False<\/code>.<\/li>\n\n\n\n<li><code>IgnorePrintAreas<\/code>: Optional. <code>True<\/code> to ignore any print areas set in the worksheet and export the entire specified range, <code>False<\/code> to respect print areas. Default is <code>False<\/code>.<\/li>\n\n\n\n<li><code>From<\/code> and <code>To<\/code>: Optional. The starting and ending page numbers to export. If the <code>Type<\/code> is PDF, and <code>From<\/code> and <code>To<\/code> are omitted, the entire specified range is exported.<\/li>\n\n\n\n<li><code>OpenAfterPublish<\/code>: Optional. <code>True<\/code> to open the file after publishing, <code>False<\/code> otherwise. Default is <code>False<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here are practical xlwings code examples:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Export a specific range to a PDF in the current directory:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book('report.xlsx')\nsheet = wb.sheets&#91;'Data']\n# Export range A1:D20\nsheet.range('A1:D20').api.ExportAsFixedFormat(0, 'MyRangeReport.pdf')<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Export the entire used range of a sheet to a high-quality PDF with document properties, ignoring print areas, and open it after creation:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book('data.xlsx')\nsheet = wb.sheets&#91;0]\nused_range = sheet.used_range\nused_range.api.ExportAsFixedFormat(\nType=0,\nFilename=r'C:\\Reports\\FullReport.pdf',\nQuality=0,\nIncludeDocProperties=True,\nIgnorePrintAreas=True,\nOpenAfterPublish=True\n)<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Export a non-contiguous range (using <code>Union<\/code>) to a PDF:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book('analysis.xlsx')\nsheet = wb.sheets&#91;'Summary']\nrange1 = sheet.range('A1:C10')\nrange2 = sheet.range('E1:G10')\n# In xlwings, we typically export one rectangular range. To export multiple areas, you might need to create a temporary sheet or use the PrintArea property.\n# A common workaround is to set a print area encompassing both ranges.\nsheet.page_setup.print_area = 'A1:C10,E1:G10'\nsheet.used_range.api.ExportAsFixedFormat(0, 'NonContiguous.pdf', IgnorePrintAreas=False)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `ExportAsFixedFormat` member of the `Range` object in Excel&apos;s object model is a powerful method &#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-2396","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2396","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=2396"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2396\/revisions"}],"predecessor-version":[{"id":3645,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2396\/revisions\/3645"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}