{"id":2261,"date":"2026-08-22T07:45:55","date_gmt":"2026-08-21T23:45:55","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2261"},"modified":"2026-03-28T12:02:21","modified_gmt":"2026-03-28T12:02:21","slug":"how-to-use-worksheetsprintout-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheetsprintout-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheets.PrintOut in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>PrintOut<\/code> method in the Worksheets collection, accessible via the xlwings API, provides a powerful way to print worksheets directly from Python. This functionality is essential for automating report generation and document distribution workflows, allowing you to control various aspects of the printing process without manual intervention in Excel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality<\/strong><br>The <code>PrintOut<\/code> method sends one or more worksheets to a printer. You can specify a range of pages, the number of copies, whether to print to a file, and other standard print settings. It is particularly useful for batch printing multiple sheets or generating physical\/digital copies of reports as part of an automated script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings<\/strong><br>The method is called on a <code>Sheet<\/code> object (representing a single worksheet) or can be applied to multiple sheets via the <code>sheets<\/code> collection. The xlwings syntax mirrors the VBA object model closely.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sheet.api.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Parameters and Their Meanings<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Parameter<\/th><th>Data Type<\/th><th>Description<\/th><th>How to Access\/Example Value<\/th><\/tr><\/thead><tbody><tr><td><code>From<\/code><\/td><td>Integer<\/td><td>The page number at which to start printing. If omitted, printing starts from the beginning.<\/td><td>Set to a number, e.g., <code>1<\/code>.<\/td><\/tr><tr><td><code>To<\/code><\/td><td>Integer<\/td><td>The page number at which to stop printing. If omitted, printing goes to the last page.<\/td><td>Set to a number, e.g., <code>3<\/code>.<\/td><\/tr><tr><td><code>Copies<\/code><\/td><td>Integer<\/td><td>The number of copies to print. Default is 1.<\/td><td>Set to a number, e.g., <code>2<\/code>.<\/td><\/tr><tr><td><code>Preview<\/code><\/td><td>Boolean<\/td><td><code>True<\/code> to have Excel invoke print preview before printing. <code>False<\/code> (default) to print immediately.<\/td><td>Use <code>True<\/code> or <code>False<\/code>.<\/td><\/tr><tr><td><code>ActivePrinter<\/code><\/td><td>String<\/td><td>Sets the name of the active printer.<\/td><td>Provide a printer name string. Often left as <code>None<\/code> to use default.<\/td><\/tr><tr><td><code>PrintToFile<\/code><\/td><td>Boolean<\/td><td><code>True<\/code> to print to a file. If <code>True<\/code>, you must specify <code>PrToFileName<\/code>.<\/td><td>Use <code>True<\/code> or <code>False<\/code>.<\/td><\/tr><tr><td><code>Collate<\/code><\/td><td>Boolean<\/td><td><code>True<\/code> (default) to collate multiple copies.<\/td><td>Use <code>True<\/code> or <code>False<\/code>.<\/td><\/tr><tr><td><code>PrToFileName<\/code><\/td><td>String<\/td><td>If <code>PrintToFile<\/code> is <code>True<\/code>, this is the name of the file to print to.<\/td><td>Provide a full file path string.<\/td><\/tr><tr><td><code>IgnorePrintAreas<\/code><\/td><td>Boolean<\/td><td><code>True<\/code> to ignore any print areas set in the worksheet and print the entire sheet.<\/td><td>Use <code>True<\/code> or <code>False<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Most parameters are optional. In xlwings, you pass them as keyword arguments, and you can omit any you don&#8217;t need, using Excel&#8217;s defaults.<\/p>\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>Basic Print:<\/strong> Print the active sheet immediately to the default printer.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book('report.xlsx')\nwb.sheets&#91;'Sheet1'].api.PrintOut()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Print Multiple Copies with Collation:<\/strong> Print two collated copies of a specific page range from &#8220;DataSheet&#8221;.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sheet = wb.sheets&#91;'DataSheet']\nsheet.api.PrintOut(From=1, To=1, Copies=2, Collate=True)<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Print to a PDF File:<\/strong> Print the entire &#8220;Summary&#8221; worksheet to a PDF file, ignoring any set print area.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>output_path = r'C:\\Reports\\summary.pdf'\nwb.sheets&#91;'Summary'].api.PrintOut(PrintToFile=True, PrToFileName=output_path, IgnorePrintAreas=True)<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Print Preview:<\/strong> Open the print preview for the first three sheets without actually printing.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>for sheet in wb.sheets&#91;:3]: # Loop through first three sheets\nsheet.api.PrintOut(Preview=True, Copies=1)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `PrintOut` method in the Worksheets collection, accessible via the xlwings API, provides a power&#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-2261","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2261","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=2261"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2261\/revisions"}],"predecessor-version":[{"id":3452,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2261\/revisions\/3452"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}