Read CSV
Read CSV
Section titled “Read CSV”Type: read-csv · Package: CSV Activities v1.0.5 · Output: DataTable
Reads a CSV file and returns its content as a DataTable, ready to loop over, filter or write to another destination.
How it works
Section titled “How it works”Reads the file at path using the given delimiter. By default it takes the first row as headers (hasHeader = true), so you access cells by name.
- Columns: with
hasHeader = true, names come from the first non-blank line (trimmed); an empty header cell gets an automatic name (Column1,Column2…). WithhasHeader = false, columns are namedColumn1,Column2… and the first line is just another data row. - Column count: set by the first line. If a row has more fields, the extra ones are dropped; if it has fewer, the missing cells stay empty (
DBNull). - Values: all text, without their surrounding quotes. Spaces around a value are kept.
- Blank lines: ignored.
- One line per record: a quoted field containing line breaks splits the record; if your file has them, open it with Excel instead.
- All in memory: it loads the whole file. It only reads; the file is not changed.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path of the CSV file. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
delimiter | string | "," | Field separator. Only the first character is used: ",", ";", "|"… For a tab, ((char)9).ToString(). |
hasHeader | bool | true | The first row holds the column names. |
encoding | string | "utf-8" | File encoding: utf-8, iso-8859-1, utf-16… If the file has a BOM, the BOM wins. See encoding. |
Output
Section titled “Output”Returns a DataTable:
- Columns: text columns named after the header (or
Column1,Column2… without a header). - Rows: one per data line. Read each cell with
str(row["Name"]), which turns empty cells into"". - Empty file (or only blank lines): a DataTable with no columns and no rows. Check it with
rowCount(table) == 0.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
File not found. | path does not exist. Check it with File Exists. |
A column named '…' already belongs to this DataTable. | Two header columns share the same name. Fix the file, or read with hasHeader = false and use Column1, Column2… |
Index was outside the bounds of the array. | delimiter is empty. Give a character. |
The process cannot access the file '…' because it is being used by another process. | The file is open in another program (for example Excel). Close it first. |
'path' is required. | The path expression evaluated to null. |
Example
Section titled “Example”Read CSV path = asset("customers.csv") delimiter = ";" → output: customersLog message = "Customers read: " + rowCount(customers)For Each items = customers itemVariable = row └─ activities: Log message = str(row["Name"]) + " — " + str(row["Email"])