IMPORT_CSV_TEXT action


Function
The action allows importing of a specified column, or whole structure from the given CSV string.


Declaration
 IMPORT_CSV_TEXT destStruct, delimiter, inputIdent_Text, timeZone, retCodeIdent_Int[, timeMaskIdent [, lineFrom [, lineTo]]] [TIME]
Parameters
destStructinColumn identifier or identifier of a local variable of the Record type.
delimiterinIdentifier of the Text type - delimiter used in a CSV file.
inputIdent_TextinString in CSV format
timeZonein

Parameter of the Text, Int or Bool type - defines interpretation of timestamps.

timeMaskIdentinIdentifier of the Text type - mask for reading a value of the Absolute time type.
retCodeIdentoutReturn code of the Int type - action success.
lineFrominParameter of the Int type - begin line.
lineToinParameter of the Int type - end line.
TIMEinKeyword.
Return code
The value of the parameter transHandle_Int. See the table of error codes.
Description
The action reads the contents of a string in CSV format. Item delimiter in a CSV file is given by a value of the parameter delimiter. The string can use the line-spacing by LF (Unix format), CR (Mac format) or CR LF sign (Dos format).
The action success is indicated by the output parameter retCodeIdent_Int. The value of 0 means the successful import, value other than 0 means an error. Depending on the parameter destStruct, the action imports following:
  • a whole structure - the parameter is a local structure identifier
  • a structure column - the parameter is the reference to a structure column


The CSV string format is described in the action EXPORT_CSV_TEXT.
If the identifier timeMaskIdent is not defined, the function expects the "dd.mm.yyyy hh:mi:ss" format for items containing an absolute time. If the parameter is defined, the format of the time is to be imported according to that mask. In case that the hh, mi or ss time components are missing, they will be automatically replaced with 0.
When real numbers are imported the separator of decimal places may be both "." (dot) and "," (comma) symbols.
When integer and real numbers are imported from CSV the thousand separator is a blank space.
If the value of the parameter timeMaskIdent is "" (empty mask), values of the Absolute time and Real type are to be converted according to the settings in the Regional and Language Options of the current user on Windows systems. For different operating systems the empty mask is automatically replaced by the value of "dd.mm.rrrr hh:mi:ss".
When the item is converted to Absolute time and is an empty string, the action interprets such item as invalid value.

If the keyword TIME is used, there is the assumption, that the occurrence times of values are saved in the CSV (the double number of columns in this CSV string).

In a case of need, the local variable destStruct will be resized. Its size is given by the number of values in the particular CSV string.

The parameter timeZone defines interpretation of timestamps. In case of empty text, timestamps are interpreted as local times. In case of defined time zone name (e.g. "Europe/London"), timestamps are interpreted as local times for given time zone. In case of integer value, timestamps are interpreted as times with fixed offset from UTC, where given value defines offset in seconds. For historical reasons boolean values are accepted: @FALSE - timestamps are interpreted as local times, @TRUE - timestamps are interpreted as times with fixed offset of 3600 seconds (1 hour) from UTC. Usage of boolean value @TRUE is not recommended and generates warning when ESL script is being saved. It is recommended to replace it with integer value.


If the parameters lineFrom and lineTo are defined, there will be imported all the lines from the line defined by LineFrom up to the line defined by the parameter lineTo. If the value of both the parameters is -1, there will be imported the whole CSV string.

The CSV delimiter (the parameter delimiter) may be obtained by calling the function %GetCSVDelimiter.

Example
To omit the parameter timeMaskIdent, declare as follows:
 


IMPORT_CSV destStruct, delimiter, fName, bMonoTimes, retCodeIdent_Int, , lineFrom, lineTo

Related pages:

Napíšte komentár