GO2cam Javascript API  6.11
GO2SCsvFile Class Reference

Class that manage CSV files. More...

Inheritance diagram for GO2SCsvFile:
GO2SAsciiFile GO2SFile

Public Member Functions

 GO2SCsvFile (String fileName, GO2SEnum::GO2SFileOpen mode=GO2SEnum::GO2SFileOpen::read_only, QChar sep=';', Boolean header=true)
 Create new or open an existing csv file.
 
GO2SEnum::GO2SError AppendRecord (Array< String > record)
 
GO2SEnum::GO2SError EditField (Number line, Number column, String newElem)
 
GO2SEnum::GO2SError EditRecord (Number index, Array< String > newRecord)
 
Number GetFieldCount ()
 
Array< String > GetLabels ()
 
Number GetRecordCount ()
 
Array< Array< String > > ReadCsv ()
 
String ReadField (Number line, Number index)
 
String ReadFieldByName (Number line, String name)
 
Array< String > ReadRecord (Number line)
 
- Public Member Functions inherited from GO2SAsciiFile
 GO2SAsciiFile (String fileName, GO2SEnum::GO2SFileOpen mode=GO2SEnum::GO2SFileOpen::read_only)
 
GO2SEnum::GO2SError Append (Number pos, String line)
 
GO2SEnum::GO2SError AppendLast (String line)
 
GO2SEnum::GO2SError DeleteLine (Number no)
 
GO2SEnum::GO2SError EditLine (Number no, String newLine)
 
Number GetLineCount ()
 
Array< String > ReadAll ()
 
String ReadLine (Number no)
 
- Public Member Functions inherited from GO2SFile
void Close ()
 Close the file.
 
String GetFilePath ()
 Get the full path (directory + name) of the file.
 
Boolean IsOpen ()
 Get if the file is open.
 
void Save ()=0
 

Detailed Description

Class that manage CSV files.

Constructor & Destructor Documentation

◆ GO2SCsvFile()

GO2SCsvFile::GO2SCsvFile ( String fileName,
GO2SEnum::GO2SFileOpen mode = GO2SEnum::GO2SFileOpen::read_only,
QChar sep = ';',
Boolean header = true )

Create new or open an existing csv file.

Parameters
[in]fileNamefull path of the file (directory + name)
[in]modeopening mode
[in]sepcolumn separator
[in]headershould we consider first line as header ? it true, 1st line should contains data name, if false 1st line contains data. This parameter is unused when starting from an empty file

Member Function Documentation

◆ AppendRecord()

GO2SEnum::GO2SError GO2SCsvFile::AppendRecord ( Array< String > record)

Add a record at the end of the file

Remarks
number of fields in the record need to be equals to GetFieldCount()
Attention
when creating a new file, header line is treated as a data line
Parameters
[in]recordnew record/line that will be added at the end of the file

◆ EditField()

GO2SEnum::GO2SError GO2SCsvFile::EditField ( Number line,
Number column,
String newElem )

Edit a field in the file

Attention
when creating a new file, header line is treated as a data line
Parameters
[in]lineline number of the record to edit
[in]columncolumn number of the field to edit
[in]newElemnew value

◆ EditRecord()

GO2SEnum::GO2SError GO2SCsvFile::EditRecord ( Number index,
Array< String > newRecord )

Replace a record

Attention
when creating a new file, header line is treated as a data line
Parameters
[in]indexline number of the record to edit
[in]newRecordnew record

◆ GetFieldCount()

Number GO2SCsvFile::GetFieldCount ( )
inline
Returns
the number of fields (columns)

◆ GetLabels()

Array< String > GO2SCsvFile::GetLabels ( )
inline
Returns
an array containings labels of columns if exist

◆ GetRecordCount()

Number GO2SCsvFile::GetRecordCount ( )
inline
Returns
the number of records (rows)

◆ ReadCsv()

Array< Array< String > > GO2SCsvFile::ReadCsv ( )
Returns
the whole csv file as a 2D array of strings

◆ ReadField()

String GO2SCsvFile::ReadField ( Number line,
Number index )

Read the field at a given line, given column (starting at 0)

Remarks
, if the file is open with header parameter at true, ReadField(0, x) works on the 2nd line of the file (see GetLabels to get the 1st line)
Parameters
[in]lineline number of the record to read
[in]indexcolumn number of the field to read

◆ ReadFieldByName()

String GO2SCsvFile::ReadFieldByName ( Number line,
String name )

Read the field with the given name, on the record at a given line

Remarks
, if the file is open with header parameter at true, ReadFieldByName(0, 'x') works on the 2nd line of the file (see GetLabels to get the 1st line)
Parameters
[in]lineline number of the record to read
[in]namecolumn name the field to read

◆ ReadRecord()

Array< String > GO2SCsvFile::ReadRecord ( Number line)
inline

Read a record at a given line (starting at 0)

Returns
le line as an array of string
Remarks
, if the file is open with header parameter at true, ReadRecord(0) works on the 2nd line of the file (see GetLabels to get the 1st line)
Parameters
[in]lineline number of the record to read