.xlsx) file.
Its primary purpose is to provide a simple way to get data out of Flatfile in a widely-used format. The plugin is triggered by a user action, typically a “Download” button configured on the workbook. It then iterates through all the sheets in the workbook (unless some are excluded), fetches the records, and compiles them into a corresponding sheet in the generated Excel file.
Use cases include:
- Allowing end-users to download a copy of their cleaned and validated data after an import
- Creating backups or snapshots of data within a Flatfile Space
- Exporting data for use in other systems that accept Excel files
- Providing a final report of all imported data, including any validation messages as comments in the Excel cells
Installation
Configuration & Parameters
The plugin is configured by passing an options object to theexportWorkbookPlugin function.
Sheet Options
ThesheetOptions parameter allows you to configure specific sheets with the following options:
Usage Examples
Basic Usage
Configuration Example
Advanced Usage with Column Transformer
Troubleshooting
Enable Debug Mode
The most important troubleshooting tool is thedebug: true option. When enabled, the plugin prints detailed logs to the console, including which sheets are being processed, which are skipped, and the status of file writing and uploading.
Check Action Operation
If the plugin does not trigger when the action button is clicked, ensure theoperation value in your workbook.config.json action exactly matches the jobName used to configure the plugin.
No Data Exported
If the exported file is empty or missing sheets, check if arecordFilter is unintentionally filtering out all records or if excludedSheets is misconfigured. The debug logs will show if sheets are being skipped. If all sheets are empty, the plugin will throw an error: No data to write to Excel file.
Notes
Server-Side Execution
This plugin must be deployed in a server-side listener environment, not in the browser.Action Configuration
For the plugin to be triggered, a correspondingaction must be configured on the Workbook in your workbook.config.json. The operation of this action must match the jobName option of the plugin (which defaults to workbook:downloadWorkbook).
File System Access
The plugin temporarily writes the.xlsx file to the /tmp directory of the execution environment, which is standard for serverless functions.
Sheet Name Sanitization
Excel sheet names have limitations (e.g., max 31 characters, no invalid characters like\ / ? * [ ]). The plugin automatically sanitizes sheet names from your workbook to comply with these rules. If a name becomes empty after sanitization, it will be replaced with a default like Sheet1, Sheet2, etc.
Default Behavior
- By default, all records from all sheets are exported
- Validation messages are included as comments in the Excel cells
- The exported file is made available in the “Files” page rather than auto-downloading
- Column headers are included in the export
- A filename is auto-generated using the workbook name and timestamp if not specified
Error Handling
The plugin wraps its entire logic in atry...catch block. If any critical step fails (fetching records, writing the file to disk, uploading the file to Flatfile), it logs the error and throws a new Error. This causes the associated job in Flatfile to fail and display the error message to the user, providing feedback on what went wrong.
