Write CSV
Writes a data table to a CSV file
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
if ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- File Path - Path of the CSV file to write to.
- Table - Data table to write to CSV file.
Options
- Separator - Separator used in CSV file. Choose from Comma(,), Semicolon(;), TAB or Space.
- Save with Encoding - Encoding used in CSV file. Choose from UTF-8, Windows 1250 to Windows 1258, ISO 8859-1 to ISO 8859-16, Macintosh and KOI8-R.
- Headers - Whether to include headers in the CSV file or not. The default value is false.
How It Works
The Write CSV node performs the following steps:
- Validates Input - Ensures the input table is in valid data table format
- Checks File Path - Verifies the target file path is valid and writable
- Creates Directory - If the directory doesn't exist, creates the necessary folders
- Prepares Headers - If Headers option is enabled, extracts column names from the data table
- Formats Data - Converts data table rows into CSV format using the specified separator
- Applies Encoding - Encodes the data using the specified character encoding
- Writes File - Creates or overwrites the CSV file with the formatted data
- Closes Stream - Ensures the file is properly closed after writing
Requirements
- File System Access - Write permissions to the target directory
- Valid Data Table - Input must be a properly formatted Robomotion data table
- Disk Space - Sufficient disk space to store the CSV file
- Directory Path - Parent directory must exist or be creatable
- File Permissions - If overwriting, the existing file must not be locked by another process
Error Handling
| Error Code | Description | Solution |
|---|---|---|
| PERMISSION_DENIED | Insufficient permissions to write to the target location | Check directory permissions and ensure write access |
| INVALID_TABLE_FORMAT | The input table is not in valid data table format | Verify the table structure before writing |
| DISK_FULL | Insufficient disk space to write the file | Free up disk space before retrying |
| INVALID_PATH | The file path contains invalid characters or format | Verify the path syntax is correct |
| FILE_IN_USE | The target file is locked by another process | Close the file in other applications before writing |
| DIRECTORY_NOT_FOUND | Parent directory doesn't exist and cannot be created | Ensure the parent directory path is valid |
| ENCODING_ERROR | Unable to encode data with specified encoding | Try a different encoding or check for incompatible characters |
Usage Examples
Example 1: Export Data Table to CSV
Export processed data to a CSV file with headers:
Input:
- File Path: "C:\Exports\processed_data.csv"
- Table: myDataTable (contains processed records)
- Separator: Comma (,)
- Save with Encoding: UTF-8
- Headers: true
Result: Creates processed_data.csv with column headers and all data rows
Example 2: Create Report Without Headers
Generate a CSV report without column headers for legacy system import:
Input:
- File Path: "/home/user/reports/daily_summary.csv"
- Table: summaryData
- Separator: Semicolon (;)
- Save with Encoding: Windows 1252
- Headers: false
Result: Creates daily_summary.csv with only data rows, no header row
Example 3: Export International Data
Export data containing special characters with appropriate encoding:
Input:
- File Path: "D:\Data\customer_names.csv"
- Table: customerData (contains names with accents and special characters)
- Separator: Comma (,)
- Save with Encoding: UTF-16
- Headers: true
Result: Creates CSV file that properly preserves special characters
Usage Notes
- Overwrite Behavior - Write CSV always overwrites the target file if it exists. Use Append CSV to add to existing files.
- Header Source - Headers are automatically derived from data table column names when Headers option is enabled.
- Encoding Selection - UTF-8 is recommended for modern systems. Use Windows-1252 for legacy Windows applications.
- Separator Choice - Comma is standard for CSV. Use semicolon for European systems where comma is a decimal separator.
- File Creation - The node creates the file and necessary parent directories if they don't exist.
- Empty Tables - Writing an empty data table creates a CSV file with headers only (if enabled) or an empty file.
- Data Type Conversion - All data is converted to strings during CSV writing. Numeric formatting is not preserved.
Tips
- Always Use Absolute Paths - Specify complete file paths to avoid ambiguity about file location.
- Test Encoding First - If unsure about encoding, test with a small sample first to ensure compatibility.
- Backup Important Files - Since Write CSV overwrites files, backup important data before running.
- Handle Errors Gracefully - Use Try-Catch blocks to handle file writing errors without stopping automation.
- Verify After Writing - Use Read CSV immediately after to verify the file was written correctly.
- Choose Appropriate Separators - If your data contains commas, consider using a different separator like semicolon or tab.
- Memory Considerations - For very large data tables, monitor memory usage during write operations.
- File Naming - Use timestamps in filenames for reports generated regularly (e.g., report_2025_01_15.csv).
Related Nodes
- Read CSV - Read CSV files back into data tables
- Append CSV - Add rows to existing CSV files without overwriting
- Split CSV - Split large CSV files into smaller chunks
- Data Table - Learn about data table creation and manipulation
-
- Create data tables programmatically