{"id":2282,"date":"2026-09-01T15:46:16","date_gmt":"2026-09-01T07:46:16","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2282"},"modified":"2026-03-28T12:18:35","modified_gmt":"2026-03-28T12:18:35","slug":"how-to-use-worksheetexportasfixedformat-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetexportasfixedformat-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.ExportAsFixedFormat in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>ExportAsFixedFormat<\/code> member of the Worksheet object in Excel&#8217;s object model is a method that enables the conversion of a worksheet into a fixed-layout format, such as PDF or XPS, directly from an Excel file. In xlwings, this functionality is exposed through the <code>api<\/code> property, which provides direct access to the underlying Excel object model. This method is particularly useful for automating report generation, distributing documents in a non-editable format, or archiving sheets with precise formatting preserved.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary purpose of <code>ExportAsFixedFormat<\/code> is to export a worksheet to a fixed-format file. It supports formats including PDF and XPS, ensuring that the layout, fonts, and graphics are maintained as they appear in Excel. This is essential for creating professional documents that require consistent presentation across different devices and platforms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>In xlwings, you call this method via the <code>api<\/code> property of a Worksheet object. The basic syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>worksheet.api.ExportAsFixedFormat(Type, Filename, Quality, IncludeDocProperties, IgnorePrintAreas, From, To, OpenAfterPublish, FixedFormatExtClassPtr)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>worksheet<\/code> refers to the xlwings Worksheet object. The parameters are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Type<\/code>: 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>: A string representing the full path and name of the output file (e.g., <code>r'C:\\Reports\\output.pdf'<\/code>). If omitted, Excel uses the default name.<\/li>\n\n\n\n<li><code>Quality<\/code>: Optional. Sets the quality of the output. Use <code>0<\/code> for Standard or <code>1<\/code> for Minimum size.<\/li>\n\n\n\n<li><code>IncludeDocProperties<\/code>: Optional. <code>True<\/code> to include document properties, <code>False<\/code> otherwise.<\/li>\n\n\n\n<li><code>IgnorePrintAreas<\/code>: Optional. <code>True<\/code> to ignore any set print areas, <code>False<\/code> to use them.<\/li>\n\n\n\n<li><code>From<\/code> and <code>To<\/code>: Optional. Integers specifying the page range to export (e.g., <code>From=1<\/code>, <code>To=3<\/code>). If not specified, all pages are exported.<\/li>\n\n\n\n<li><code>OpenAfterPublish<\/code>: Optional. <code>True<\/code> to open the file after export, <code>False<\/code> otherwise.<\/li>\n\n\n\n<li><code>FixedFormatExtClassPtr<\/code>: Optional. A pointer for extended format classes, typically left as <code>None<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Most parameters are optional; in practice, only <code>Type<\/code> and <code>Filename<\/code> are commonly required. For example, to export as PDF with default settings, you might specify just these two.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example:<\/strong><br>Below is an xlwings code instance that demonstrates exporting the active worksheet to a PDF file. This example assumes Excel is already open with a workbook, and it sets a few optional parameters for clarity.<\/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\nwb = app.books.active\nws = wb.sheets.active\n\n# Export the active worksheet to PDF\noutput_path = r'C:\\Users\\Public\\Documents\\Monthly_Report.pdf'\nws.api.ExportAsFixedFormat(\nType=0, # 0 for PDF\nFilename=output_path,\nQuality=0, # Standard quality\nIncludeDocProperties=True,\nIgnorePrintAreas=False,\nOpenAfterPublish=False\n)\n\nprint(f\"Worksheet exported to {output_path}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `ExportAsFixedFormat` member of the Worksheet object in Excel&apos;s object model is a method that en&#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-2282","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2282","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=2282"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2282\/revisions"}],"predecessor-version":[{"id":3483,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2282\/revisions\/3483"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}