Skip to main content
Version: 2.50.0-LTS

Generate file

This action allows you to construct files on the fly and let users download it.

Options

OptionDescription
TypeType of file to be generated. Types: CSV, Text and PDF
File nameName of the file to be generated
DataData that will be used to construct the file. Its format will depend on the file type, as specified in the following section
DebounceDebounce field is empty by default, you can enter a numerical value to specify the time in milliseconds after which the action will be performed. ex: 300

CSV Data Format

To use the CSV file format, the data field should contain an array of objects. ToolJet assumes that the keys in each object are the same and represent the column headers of the CSV file.

Example:

{{
[
{ name: 'John', email: '[email protected]' },
{ name: 'Sarah', email: '[email protected]' },
]
}}

Using the above code snippet will generate a CSV file with the following content:

Text Data Format

To use the Text file format, the data field should contain a string.

If you want to generate a text file based on an array of objects, you need to stringify the data before providing it.

For example, if you are using the table component to provide the data, you can enter {{JSON.stringify(components.table1.currentPageData)}} in the Data field.

PDF data format

The PDF data format supports two types of input: either a string or an array of objects. When using an array of objects, the resulting PDF will display the data in a tabular format with columns and rows. On the other hand, if a string is provided, the generated PDF will consist of plain text.