How to Auto-Fill PDF Form Fields Using an Excel Lookup Table
Question details
The user wants to automatically populate multiple related fields in a PDF form based on a single entry, mapping data from a large Excel dataset.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating advanced interactive PDF forms that require fetching data from an external spreadsheet to populate linked fields automatically.
- Observed behavior
- A simple JavaScript solution is insufficient due to the large number of possible options in the Excel file, necessitating a structured lookup table approach.
Ensure your Excel data is properly organized with clear column headers and convert it into a format that can be parsed by JavaScript, such as JSON or a structured array, as standard PDFs cannot natively query live .xlsx files.
Implement Document-Level JavaScript for Table Lookups
Use this method to embed your Excel dataset directly into the PDF as a document-level array, allowing a trigger field to pull and display related values.
Because standard PDF forms run in a restricted sandbox, they cannot establish direct database connections to local Excel files. The most reliable approach is to embed your lookup data directly inside the PDF file's background code.
Format your Excel spreadsheet into a JavaScript array or JSON object. You can use Excel formulas or an online CSV-to-JSON converter to structure your rows and columns into usable JavaScript code.
Open your PDF editor, navigate to the JavaScript tools (e.g., Tools > JavaScript > Document JavaScripts), create a new script, and paste your formatted data array here. Name the array variable something easily identifiable, like 'lookupData'.
Right-click the primary form field (such as a Dropdown or Text box) that the user will interact with, select 'Properties', and navigate to the 'Format' or 'Validate' tab.
In the trigger field's custom script area, write a function that takes the user's input, searches the 'lookupData' array for a match, and uses 'this.getField("TargetFieldName").value' to populate the secondary form fields with the corresponding data.

Create and Manage PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily create interactive forms, insert text fields, checkboxes, and dropdowns, and seamlessly handle standard form data workflows.
- 1. Open WPS PDF: Launch WPS Office and open your existing PDF document or create a blank one using the PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view the available interactive form controls.
- 3. Insert Form Fields: Click on 'Text Field', 'Combo Box', or other elements, then click on the document area where you want to place them.
- 4. Edit Field Properties: Double-click the newly created field to open its properties panel, where you can define names, export values, and formatting.

Frequently Asked Questions
Can a PDF directly read data from an active Excel (.xlsx) file?
No, standard PDF JavaScript cannot directly connect to or query a live Excel file due to security restrictions. You must export the Excel data to a compatible format and embed it within the PDF as a JavaScript array.
How do I add a document-level JavaScript to my PDF?
In advanced PDF editors like Adobe Acrobat, you can add document-level scripts by going to Tools > JavaScript > Document JavaScripts. This allows the code and lookup data to load seamlessly as soon as the PDF is opened.
What if my Excel lookup table is too large for a PDF array?
If the dataset contains excessive rows, embedding it directly might degrade the PDF's performance. In such cases, consider using a web-based form connected to a backend database instead of relying on a standalone offline PDF file.




