PDF Security & Access Issues

How to Open an Attached Excel File from a PDF Button

Phi Hung VoPhi Hung Vo Nov 5, 2026 869 views

Question details

The user wants to create an interactive PDF button that directly launches a specific embedded Excel workbook in the Excel application, rather than just opening the attachments pane.

How to Open an Attached Excel File from a PDF Button
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive PDF document where users can seamlessly open a bundled Excel attachment by clicking a custom button.
Observed behavior
By default, clicking an attachment link might only reveal the attachments panel. The goal is to programmatically trigger the external Excel application to open the specific embedded file.
Before you start

Verify that the Excel file is fully embedded as an attachment in your PDF document, and ensure your PDF software's security settings permit the launching of external applications via JavaScript.

Solution 1Recommended

Use JavaScript to Launch the Embedded Attachment

Configure the button's properties to run a specific JavaScript command that extracts and launches the attached file upon a mouse click.

To bypass the default attachment pane and directly open the file, you must use a short JavaScript action. This script targets the embedded file by its exact name and tells the PDF viewer to open it in its native application.

1
Add a Button Field

Open your PDF document in an advanced PDF editor, enter the form-editing mode, and insert a new 'Button' field onto the page.

2
Access Button Properties

Right-click the newly created button and select 'Properties' from the context menu. Navigate to the 'Actions' tab.

3
Set the Action Trigger

In the 'Select Trigger' dropdown menu, choose 'Mouse Up'. In the 'Select Action' dropdown, choose 'Run a JavaScript', then click the 'Add' button.

4
Input the Launch Script

In the JavaScript Editor window, type: this.exportDataObject({cName: "MyFile.xlsx", nLaunch: 2});. Replace "MyFile.xlsx" with the exact name and extension of your attached Excel file.

5
Save and Test

Click 'OK' to close the editor, exit form-editing mode, and save your document. Click the button to test the script; the Excel file should now open.

Security Prompts: Because opening external files can be a security risk, most PDF viewers will display a warning prompt the first time the button is clicked. Users must authorize the action to allow the file to open.
Efficient PDF Editing

Easily Manage and Open PDF Attachments with WPS Office

WPS Office provides an all-in-one suite with a built-in PDF editor that allows you to easily add, manage, and natively view attached files like Excel spreadsheets without needing complex scripts.

  1. 1. Open Your PDF: Launch WPS Office and open your PDF document containing the embedded files.
  2. 2. Access the Attachments Pane: Click on the 'Attachment' icon (shaped like a paperclip) located on the left-hand navigation pane.
  3. 3. Open the File Natively: Double-click the attached Excel file from the list. WPS Office will seamlessly launch the file in its built-in spreadsheet editor.
Add and manage embedded Excel workbooks effortlessly.Highly compatible with Microsoft Excel (.xlsx) formats.All-in-one suite allows you to view the PDF and edit the attached Excel file in the exact same application environment.Free and lightweight alternative to heavy PDF software.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the PDF button still only open the attachments pane?

If the JavaScript action isn't configured correctly or the 'nLaunch: 2' parameter is omitted, the PDF viewer will default to extracting the file to the attachments pane rather than launching the external application.

Can I use this JavaScript code for Word or image attachments?

Yes, the exportDataObject script works for various file types. Simply change the cName parameter in the script to match the exact filename and extension of your embedded file, such as 'document.docx'.

Why is the embedded Excel file not opening when I click the button?

Ensure the file name in your script perfectly matches the attachment's name (it is case-sensitive). Additionally, check your PDF viewer's trust and security settings, as strict modes often block scripts from launching external files.

Will this PDF button work on mobile PDF viewers?

Most mobile PDF viewers do not support advanced JavaScript actions like launching external application data. This interactive button solution is primarily intended for robust desktop PDF software.