CSV/TXT package guide
Read a delimited text file into a named session, get its Table, and close the session. Use Open, then Read into $orders$, then Close.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested. See Packages.
Prerequisites
- A local file that the Device's account can read. You do not need a spreadsheet app. A short path starts in the Run's working folder.
- Open reads the whole file at once. If the file changes later, Open it again.
How the file is read:
- Quoted values, doubled quotes (
"") and line breaks inside quotes work. Lines can end in CR, LF or CRLF. - Every cell is text (String), also numbers.
- Short rows get empty cells. Long rows add columns.
- Empty headers become
Column1,Column2, and so on. A header of only spaces or tabs stays as it is, unless a trim option removes all of it. - Limits: 64 MB file, 16,777,216 characters of text, 100,000 rows and 1,000,000 cells. The header row counts too.
Create samples/orders.csv for the examples:
id,name,qty
A1,Ada,2
A2,Bea,10Shared fields
Open, Read and Close all use this field.
| ID | Field | Type; default; requirement | Use |
|---|---|---|---|
session | Session name | Stringdefault ""optional in editor, needed to run | The session name, for example orders. The editor lets you leave it empty, but the step then fails. Use the same name in Open, Read and Close. A session ends with the Run. The name is only a label, not a path. |
Actions
Close (csvTxtClose)
End the session. The file is not changed.
Inputs
Uses the shared fields: session.
Outputs
None.
Example
Open samples/orders.csv with session=orders, then Read it. Set Close session=orders.
Expected result
The orders session ends. A later Read or Close with that name fails until Open starts it again. Your Table variable keeps its rows.
Open (csvTxtOpen)
Read the file into a session. Use Read next to get the Table. A session with the same name is replaced.
Inputs
| ID | Field | Type; default; requirement | Use |
|---|---|---|---|
file | File path | Stringdefault ""required | A file that exists, for example samples/. A short path starts in the Run's working folder. |
contains | Contains header | Booleandefault falseoptional | true: the first row gives the column names. false: the first row is data, and the columns are Column1, Column2, and so on. |
delimeter | Delimiter | Csvdefault commaoptional | comma: commas. tab: tabs. regionallistseparator: the list separator of the Windows region. new: one value per line. other: the text in specific. |
specific | Specific Delimiter | Stringdefault ""optional | With delimeter=, the separator, for example ; or ::. It must not be empty. Other choices ignore it. |
trim | Trim leading spaces | Booleandefault falseoptional | true: remove spaces and tabs at the start of each value, headers too. |
trim | Trim trailing spaces | Booleandefault falseoptional | true: remove spaces and tabs at the end of each value, headers too. |
encoding | Encoding | Csvdefault FILE_optional | FILE_: auto (UTF-8 if not sure). UTF8: UTF-8. unicode and UTF16: UTF-16. ansi: Windows-1252. win1251: Windows-1251. |
Also uses the shared fields: session.
Outputs
None.
Example
Create samples/orders.csv as shown in Prerequisites. Set session=orders, filePath=samples/orders.csv, containsHeader=true, delimeter=comma, encoding=FILE_ENCODING, trimLeadingSpace=false, trimTrailingSpace=false.
Expected result
Session orders has String columns id,name,qty and two rows. Open gives no Table; use Read next. Open fails on a missing file, an empty session name, an empty specificDelimiter with other, or a file over the limits. An empty file gives an empty table.
Read (csvTxtReadFrom)
Get the Table from the session. The file is not read again.
Inputs
Uses the shared fields: session.
Outputs
| ID | Type | Result / editor field |
|---|---|---|
result | Table | The Table of the session, for example in $orders$. Field: Assign value to the variable. |
Example
Open the sample file with session=orders and containsHeader=true. Set Read session=orders. Put result in Table variable $orders$.
Expected result
$orders$ has rows A1,Ada,2 and A2,Bea,10. Numbers stay as String cells. Another Read gives the same Table. To see changes in the file, Open it again. An unknown or closed session fails.