Data Import & Export

How to Export Multiple Excel Sheets to PDF Using Office Scripts

Kushani NimanthikaKushani Nimanthika Oct 10, 2026 869 views

Question details

The user needs to export multiple Excel worksheets into a PDF file using Office Scripts while maintaining configured print areas and page breaks.

Exporting Multiple Excel Sheets to PDF with Office Scripts
Product
Microsoft Excel
Device & OS
not provided
Scenario
Automating the conversion of multi-sheet Excel workbooks to PDF format in a cloud environment.
Observed behavior
Office Scripts lacks a direct API for PDF export, and standard Power Automate conversion actions fail to preserve custom page breaks and print areas.
Before you start

Ensure you have access to Power Automate and an active Microsoft 365 subscription, as you will need to combine cloud flows with your scripts to generate the PDF.

Solution 1Recommended

Use Power Automate with Office Scripts

Since Office Scripts cannot generate PDFs directly, you can pass a list of worksheets from your script to Power Automate to handle the file conversion.

This method requires creating an Office Script to return the target worksheet names, then using a Power Automate flow to extract the data and convert it into a PDF document.

1
Create the Office Script

Open Excel on the web, go to the 'Automate' tab, and click 'New Script'. Write a script that loops through the workbook and returns an array of the sheet names you want to export.

2
Set up a Power Automate Flow

Log into Power Automate and create a new flow. Add the 'Run script' action from the Excel Online connector to execute the script you just created.

3
Convert File to PDF

Add the 'Convert file' action (via OneDrive for Business or SharePoint connectors) in your flow, targeting the Excel workbook, and set the target format to PDF.

4
Test Layout Behavior

Run the flow and open the generated PDF. Verify the layout, as Power Automate's default conversion engine may alter custom page breaks and print areas.

Use Power Automate with Office Scripts
Layout Limitations: The native Power Automate 'Convert file' action does not reliably preserve custom Excel print areas or manual page breaks.

Easily Export Multiple Sheets to PDF with WPS Office

Skip complex scripting and Power Automate flows. WPS Spreadsheet offers a built-in, one-click feature to export multiple worksheets to PDF while perfectly preserving your custom page breaks and print areas.

  1. 1. Open your Workbook in WPS Spreadsheet: Launch WPS Office and open the Excel file containing the sheets you want to export.
  2. 2. Access the PDF Export Tool: Click on 'Menu' in the top left corner, then select 'Export to PDF' from the dropdown list.
  3. 3. Select Sheets to Export: In the export dialog box, choose the 'Entire Workbook' option or manually check the specific sheets you wish to include in the PDF.
  4. 4. Export and Save: Adjust any necessary export settings and click 'Export' to generate a perfectly formatted PDF document instantly.
Native support for batch-exporting entire workbooks or specific multiple sheets to PDF.Perfectly preserves custom page breaks, margins, and predefined print areas.Highly compatible with Microsoft Excel (.xlsx and .xls) formats.Free and lightweight alternative to complex automation setups.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't Power Automate preserve my Excel page breaks?

The default 'Convert file' action in Power Automate uses a generic cloud rendering engine. It extracts the raw data and auto-fits it to a standard page size, completely bypassing custom print areas and page breaks configured in the desktop Excel app.

Is there a direct API in Office Scripts to save a file as PDF?

No. Currently, Office Scripts lacks a native method or API to directly save, export, or convert a workbook into a PDF format. It must be paired with an external automation tool like Power Automate.

Can VBA handle PDF exports better than Office Scripts?

Yes. If you are using desktop Excel, VBA includes a direct 'ExportAsFixedFormat' method. Unlike cloud-based Office Scripts, this VBA method perfectly respects local print settings, including page breaks and predefined print areas.