HotXLS Docs

OpenCSV method

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;
FileNameWideString. Full or relative path to the delimited text file
StreamTStream. Complete CSV or TSV data to import
ASeparatorWideChar. Use #0 to auto-detect comma, semicolon, tab, or pipe from the first populated line; otherwise pass the separator to use
ADetectTypesBoolean. 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
AOptionsTXlsCsvImportOptions. 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