Read a CSV or Excel file
Turn an arriving file into rows a workflow can work with, including awkward extracts with preamble, trailers or an unusual delimiter.
Most file-driven workflows start the same way: a file arrives, and a parse step turns it into a table the rest of the chain can read. Parse (Read) CSV and Parse (Read) XLSX are those steps, and their options exist because real extracts are rarely clean. A custodian file may open with three lines of preamble, close with a trailer, and use semicolons.
Add either step directly after a File Received trigger or a Load File action, then set the options below in the side panel. Both sit in the Data group of the action list. For how the parsed table reaches the next step, see Action Inputs.
For PDFs, scans and other documents that are not rows and columns, see Read documents instead.
Where the file comes from
A parse step reads the file handed to it by the step before:
- After a File Received trigger, it reads the file that started the run. No extra step is needed.
- After a Manual or Schedule trigger, which carry no file, add a Load File step first and pick the file in its File field.
Load File can also read a file from a context variable instead of a fixed file. If the workflow declares a context variable of type File, the File picker lists the workflow's file variables under Context variables, above Select a file under Files. Pick one and each run fills in the file it is given, for example the file chosen in the run dialog. The field then shows the variable as {{ name }}, and the file preview is hidden, since there is no file until the run starts. See Context variables.
Parse (Read) CSV
| Option | What it does |
|---|---|
| Delimiter | The character separating fields. A new step shows a comma. Clear it to detect the delimiter per file |
| Skip Rows | Rows to ignore at the top of the file, before the header row |
| Skip Footer Rows | Rows to ignore at the bottom, for trailer lines that are not data |
Skip Rows and Skip Footer Rows are folded under More options, closed by default. The first row after any skipped rows is always treated as the header.
Letting SPARK detect the delimiter
Leave Delimiter empty and each file is inspected on arrival. SPARK tries a comma, a semicolon, a tab and a pipe, and keeps whichever one splits the header row into the most fields. Rows you skip with Skip Rows are left out of the detection, so a preamble cannot mislead it.
The header is the deciding row on purpose. Extracts often have ragged bodies: a 66-column header followed by cash lines that carry only a handful of fields. Judging the whole file would count that raggedness against the real delimiter and in favour of some incidental character that happens to appear consistently. The header is the one row guaranteed to be complete, so it is the one that votes.
Detection also parses the header properly rather than counting characters, so a quoted column name containing a separator, such as "Name, First";Age, does not vote for the character inside the quotes. When none of the four candidates splits the header, SPARK makes one more attempt to recognise another separator, and accepts it only if it is not a letter or a digit.
Set the delimiter explicitly when you know it and the files are consistent; that removes any doubt. Reach for detection when one workflow ingests files from several sources.
If a file cannot be read at all, the step fails with Unable to detect delimiter from CSV content. That usually means the header is empty, the file is not delimited text, or the rows you skipped did not include everything before the header. Open the run in Executions and check Skip Rows first.
If Skip Footer Rows asks for more rows than the file has, the step fails with a message naming how many rows the file holds. Blank lines at the very end of the file do not count as footer rows.
Fixed-width and other text files
A text file with columns defined by position rather than a separator is read by a different step, Parse TXT File. Its Mode switch offers Delimited and Fixed Width:
- Delimited reads separated text, with a delimiter picker (Auto, Comma (,), Semicolon (;), Tab, Pipe (|), Space or Custom).
- Fixed Width shows a Colspecs box under Fixed Width Options, one
start,endcharacter range per line, for example0,8.
Both modes also let you say whether the first line holds column names, skip lines at the top, and drop rows that are entirely empty.
Parse (Read) XLSX
| Option | What it does |
|---|---|
| Sheet Name | The sheet to load, by its name. Leave empty to load the first one |
| Header Row | Which row holds the column headers, counted from zero |
| Skip Rows | Rows to ignore at the top of the sheet, before the header row |
Excel files need no delimiter, so the equivalent question is which sheet and which row the headers are on. Naming the sheet is worth doing whenever the workbook has more than one, since "the first sheet" can change without warning when someone re-saves the file. If the named sheet is not in the workbook, the step fails with a message that lists the sheets it does have, so a renamed tab is quick to spot.
The step reads a file that is really a spreadsheet. If the file arriving is text, such as a CSV saved with an .xlsx name, the step fails and its message quotes the start of what arrived. Use Parse (Read) CSV for those.
Check what the step read
Open the run in Executions and click the parse step. Its Output shows the rows it produced as a table, with a line such as 10 of 52 records above it and Export and View all at its right. View all opens every row under the step's name, with a pager at the foot. This is the quickest way to confirm the header row landed where you expected before the data reaches a Save Record step.
What comes next in the chain
A parse step outputs a Table, which is what the steps that follow expect:
- Map Data Fields to line the source columns up with your attributes.
- Filter Records to drop the rows you do not want.
- Save Record to write the result into a data object.