How to Open an Attached Excel File from a PDF Button
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.

- 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.
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.
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.
Open your PDF document in an advanced PDF editor, enter the form-editing mode, and insert a new 'Button' field onto the page.
Right-click the newly created button and select 'Properties' from the context menu. Navigate to the 'Actions' tab.
In the 'Select Trigger' dropdown menu, choose 'Mouse Up'. In the 'Select Action' dropdown, choose 'Run a JavaScript', then click the 'Add' button.
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.
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.
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. Open Your PDF: Launch WPS Office and open your PDF document containing the embedded files.
- 2. Access the Attachments Pane: Click on the 'Attachment' icon (shaped like a paperclip) located on the left-hand navigation pane.
- 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.

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.




