Imports a CSV or TSV text file or stream into a workbook worksheet
TXLSWorkbook.OpenCSV provides the classic XLS facade entry
point, and TXLSXWorkbook.OpenCSV provides the same import
behaviour for the XLSX facade
Syntax
function OpenCSV(FileName: WideString): Integer;
function OpenCSV(FileName: WideString; ASeparator: WideChar; ADetectTypes: Boolean): Integer;
function OpenCSV(Stream: TStream): Integer;
function OpenCSV(Stream: TStream; ASeparator: WideChar; ADetectTypes: Boolean): Integer;
function OpenCSV(const FileName: WideString; const AOptions: TXlsCsvImportOptions): Integer;
function OpenCSV(Stream: TStream; const AOptions: TXlsCsvImportOptions): Integer;
| FileName | WideString. Full or relative path to the delimited text file |
| Stream | TStream. Complete CSV or TSV data to import |
| ASeparator | WideChar. Use #0 to auto-detect comma, semicolon, tab, or pipe from the first populated line; otherwise pass the separator to use |
| ADetectTypes | Boolean. When True, fields are promoted to numeric, date/time, or Boolean variants where possible. When False, fields remain text, which is useful for leading zeroes and long identifiers |
| AOptions | TXlsCsvImportOptions. Use TXlsCsvImportOptions.Default for deterministic defaults on every supported compiler, then set Separator, DetectTypes, SkipRows, or AutoTrim as needed |
behaviour
The importer detects UTF-8 and UTF-16 byte-order marks, parses RFC
4180-style quoted fields, and writes the parsed grid into a worksheet
Calling Open(FileName) on a .csv or
.tsv path routes to this importer automatically
Example
Workbook.OpenCSV('orders.csv');
Workbook.OpenCSV('part-numbers.tsv', #9, False);
Options := TXlsCsvImportOptions.Default;
Options.SkipRows := 1;
Options.AutoTrim := True;
Workbook.OpenCSV('orders-with-heading.csv', Options);
See also