PALATINELABSDocsENES

Pages

↑↓ to moveEnter to openEsc to close

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.

Jump to actions

Prerequisites

How the file is read:

Create samples/orders.csv for the examples:

id,name,qty
A1,Ada,2
A2,Bea,10

Shared fields

Open, Read and Close all use this field.

IDFieldType; default; requirementUse
sessionSession nameStringdefault ""optional in editor, needed to runThe 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.

Back to actions

Open (csvTxtOpen)

Read the file into a session. Use Read next to get the Table. A session with the same name is replaced.

Inputs

IDFieldType; default; requirementUse
filePathFile pathStringdefault ""requiredA file that exists, for example samples/orders.csv⁠. A short path starts in the Run's working folder.
containsHeaderContains headerBooleandefault falseoptionaltrue⁠: the first row gives the column names. false⁠: the first row is data, and the columns are Column1⁠, Column2⁠, and so on.
delimeterDelimiterCsvDelimiterdefault commaoptionalcomma⁠: commas. tab⁠: tabs. regionallistseparator⁠: the list separator of the Windows region. newLine⁠: one value per line. other⁠: the text in specificDelimiter⁠.
specificDelimiterSpecific DelimiterStringdefault ""optionalWith delimeter=other⁠, the separator, for example ; or ::⁠. It must not be empty. Other choices ignore it.
trimLeadingSpaceTrim leading spacesBooleandefault falseoptionaltrue⁠: remove spaces and tabs at the start of each value, headers too.
trimTrailingSpaceTrim trailing spacesBooleandefault falseoptionaltrue⁠: remove spaces and tabs at the end of each value, headers too.
encodingEncodingCsvEncodingdefault FILE_ENCODINGoptionalFILE_ENCODING⁠: auto (UTF-8 if not sure). UTF8⁠: UTF-8. unicode and UTF16LE⁠: 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.

Back to actions

Read (csvTxtReadFrom)

Get the Table from the session. The file is not read again.

Inputs

Uses the shared fields: session.

Outputs

IDTypeResult / editor field
resultTableThe 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.

Back to actions