The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



ExportAsCSV


Unit:SDL_datatable
Class: TDataTable
Declaration: [1] function ExportAsCSV (FName: string; Precision: integer; Delimiter: TCSVDelimiters; IncludeColHeaders, IncludeRowHeaders: boolean): string;
[2] function ExportAsCSV (FName: string; Precision: integer; Delimiter: TCSVDelimiters; IncludeColHeaders, IncludeRowHeaders, IncludeRowAttributes: boolean): string;
[3]function ExportAsCSV (FName: string; Precision: integer; Delimiter: TCSVDelimiters; IncludeColHeaders, IncludeRowHeaders, IncludeRowAttributes, IncludeComment: boolean): string;

The method ExportAsCSV writes the contents of the data table along with optional additional information (headers, etc.) to the CSV file FName. The parameter Precision controls the number of significant digits used for storing the data. The delimiting character is specfied by the parameter Delimiter. If Delimiter is set to csvUnknown it defaults to csvComma.

The parameters IncludeColHeaders and IncludeRowHeaders control whether the column and row headers are exported, as well. Nominal and ordinal values are exported using their nominal identifiers.

The second overloaded version of the method provides the extra parameter IncludeRowAttributes which controls whether the row attributes are exported as well. The third version provides the additional parameter IncludeComment which determines whether the comment of data table is included in the CSV file.

The method returns an error message string if any problem occurs during opening the file (e.g. 'file access denied' for read-only files).

Hint 1: Please note that the CSV format has never been standardized, and thus a plethora of different sub-versions exists. Further, the decimal separator and the thousand separator character change between different languages, contributing to even greater confusion. For example, in German implementations the comma is replaced by the semicolon in order to be able to use the comma as a decimal separator. Thus the selection of the delimiter depends on the system which will be used to read the CSV file.

Hint 2: ExportAsCSV triggers the OnPercentDone event to provide feedback during time consuming write operations.

Hint 3: The OnExportText event allows to modify the exported lines immediately before writing a line to the disk.



Last Update: 2023-Dec-14