CSVReader¶
-
MacroModule
¶ genre File
authors Jan Hendrik Moltz
,Hans Meine
package FMEstable/ReleaseMeVis
definition CSVReader.def keywords CSV
,file
,read
,parse
Purpose¶
Reads a CSV file, making it possible to select rows and extract column values.
Usage¶
Choose the filename of a CSV file. Select a row index and up to eight column indices in order to display the values of the corresponding entries. Use the “All Rows” tab for viewing all rows (and potentially sorting by a particular column).
Details¶
The CSV file is parsed using Python’s csv module.
Some parameters of the module - Delimiter
, Quote Char
and Skip Initial Space
- can be set. See also the section on dialects and formatting parameters in the Python documentation.
Internally, the content of the file is stored in a list of lists which can be addressed by row and column indices.
Numerical columns are recognized, which enables proper numerical sorting (by clicking on column headers in the “All Rows” tab).
Tips¶
It is also possible to load CSV files using drag & drop.
Values from the currently selected row can not only be accessed via the field interface, but also via scripting:
row = ctx.module('CSVReader').call('getSelectedRow') # returns a list
record = ctx.module('CSVReader').call('getSelectedRecord') # returns a dict, indexed by column names
Numbers among the values will already have the appropriate Python type (int/float).
This is useful in conjunction with the fact that the listview (from the “All Rows” tab) can be embedded in other panels using the Panel MDL control:
Panel {
module = CSVReader
panel = listView
}
Parameter Fields¶
Field Index¶
Auto Load : Bool |
Delimiter : String |
Skip Initial Space : Bool |
Column1 : String |
Encoding : Enum |
trueFilename : String |
Column2 : String |
Filename : String |
Value1 : String |
Column3 : String |
First Row Contains Header : Bool |
Value2 : String |
Column4 : String |
Headers found (for copy-pasting into column fields) : String |
Value3 : String |
Column5 : String |
Load : Trigger |
Value4 : String |
Column6 : String |
Number Of Columns : Integer |
Value5 : String |
Column7 : String |
Number Of Rows : Integer |
Value6 : String |
Column8 : String |
Quote Char : String |
Value7 : String |
dataChanged : Trigger |
Row Index : Integer |
Value8 : String |
Visible Fields¶
Filename¶
-
name:
filename
, type:
String
¶ Name of the CSV file. May use $(HOME) etc., as in
LocalFileName
.
Delimiter¶
-
name:
delimiter
, type:
String
, default:
,
¶ Character that separates entries within a row, usually “,” or “;”.
Use “t” in order to enter a <tab> character as delimiter for TSV files (“tab-separated values”).
Quote Char¶
-
name:
quoteChar
, type:
String
, default:
"
¶ Character used for quoting entries containing the delimiter or newlines.
Skip Initial Space¶
-
name:
skipInitialSpace
, type:
Bool
, default:
FALSE
¶ Flag that enables removing spaces at the beginning of a parsed entry.
First Row Contains Header¶
Encoding¶
-
name:
encoding
, type:
Enum
, default:
Default
¶ Encoding that is used to open the .csv file.
Feel free to add other encodings, if needed.
Values:
Title | Name | Description |
---|---|---|
Default | Default | Uses the default encoding of the operating system. |
utf-8 | utf-8 | Uses uft-8 encoding. |
Auto Load¶
-
name:
autoLoad
, type:
Bool
, default:
TRUE
¶ Load data automatically when the filename or CSV reading settings changes.
Number Of Rows¶
-
name:
numberOfRows
, type:
Integer
, persistent:
no
¶ Number of rows found in the CSV file.
Number Of Columns¶
-
name:
numberOfColumns
, type:
Integer
, persistent:
no
¶ Number of columns found in the CSV file (maximum from all data rows).
Row Index¶
-
name:
rowIndex
, type:
Integer
, default:
0
, minimum:
0
¶ Index of the row to be selected (starting with 0 in the first data row, potentially skipping the header).
Column1¶
-
name:
column1
, type:
String
, default:
0
, deprecated name:
columnIndex1
¶ Index or name of the column to be read from the selected row into
Value1
.Names are supported if
First Row Contains Header
is set; in the “Settings” tab, there is aHeaders found (for copy-pasting into column fields)
field for easier copy-pasting of names into the column fields.
Column2¶
Column3¶
Column4¶
Column5¶
Column6¶
Column7¶
Column8¶
Value1¶
Headers found (for copy-pasting into column fields)¶
-
name:
headers
, type:
String
, persistent:
no
¶ Headers found in current file (if
First Row Contains Header
is set). Intended for easy copy-pasting of column names intoColumn1
etc.