Csv Delphi ActiveX Reference Documentation

TChilkatCsv

Current Version: 11.5.0

Chilkat.Csv

Read, edit, sort, and write CSV or delimiter-separated data in memory.

Chilkat.Csv is a practical in-memory table class for working with CSV and other delimiter-separated text formats. It can load CSV data from files or strings, access cells by row/column index or column name, manage header rows, insert and delete rows or columns, sort records, search for matching rows, and write the result back using configurable delimiters, quoting rules, character encodings, and line endings.

In-memory CSV table

Load CSV data, modify cells, add rows, delete rows or columns, and write the updated table back to a file or string.

Header and named columns

Use a header row to access fields by column name instead of only by numeric column index.

Cell and row operations

Read and update individual cells, insert columns, remove data, find matching rows, and sort the table as needed.

Delimiter control

Work with comma-separated data or other delimiter-separated formats by configuring the delimiter character.

Quoting and output formatting

Control quoted fields, forced quoting, output line endings, explicit character encodings, and UTF-8 BOM emission.

Excel worksheet loading

Load worksheet data from an opened .xlsx ZIP container when CSV-style access to spreadsheet content is needed.

Common pattern: Load CSV data, specify whether the first row is a header, access or modify cells by index or column name, perform any row, column, search, or sort operations, then save the table using the delimiter, charset, quoting, BOM, and line-ending settings required by the target system.

Object Creation

var
obj: TChilkatCsv;
...
begin
obj := TChilkatCsv.Create(Self);
...
// When finished, free the object instance.
obj.Free();

Properties

AutoTrim
property AutoTrim: Integer

Controls whether leading and trailing whitespace is removed from cell values returned by GetCell and GetCellByName.

  • When 1, returned cell values are automatically trimmed.
  • When 0, returned cell values are left unchanged.

top
Crlf
property Crlf: Integer

Controls the line endings used when the CSV is written by SaveFile, SaveFile2, or SaveToString.

  • When 1, records are separated by CRLF line endings.
  • When 0, records are separated by LF line endings.

top
DebugLogFilePath
property DebugLogFilePath: WideString

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
Delimiter
property Delimiter: WideString

Specifies the character used to separate fields within each CSV record. The default delimiter is a comma (,).

When loading CSV data, Chilkat automatically detects the delimiter if this property was not explicitly set. A semicolon (;) is commonly used in locales where a comma is used as the decimal separator.

Creating a new CSV: To use a delimiter other than a comma, set this property before adding rows or columns.

Vertical-bar delimiter: If this property is explicitly set to |, and EnableQuotes has not been explicitly set, EnableQuotes defaults to 0. This allows quotation marks to be treated as ordinary characters in vertical-bar-delimited data.

top
EnableQuotes
property EnableQuotes: Integer
Introduced in version 9.5.0.71

Controls whether double quotation marks are interpreted as CSV field delimiters when reading or writing data.

When 1, content enclosed in double quotation marks is treated as a single field, even when it contains delimiter characters, carriage returns, or line feeds. The default value is 1.

More Information and Examples
top
EscapeBackslash
property EscapeBackslash: Integer
Introduced in version 9.5.0.44

Controls whether the backslash character (\) is treated as an escape character when reading or writing CSV data.

The default value is 0.

top
HasColumnNames
property HasColumnNames: Integer

Indicates whether the first record contains column names rather than data.

Set this property to 1 before loading CSV data when the first record is a header row. Chilkat will then load the field names as column names and exclude the header row from the data-row count.

More Information and Examples
top
LastBinaryResult
property LastBinaryResult: OleVariant readonly

This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. It is only accessible if Chilkat.Global.KeepBinaryResult is set to 1. This feature allows for the retrieval of large varbinary results in an SQL Server environment, which has restrictions on returning large data via method calls, though temp tables can handle binary properties.

top
LastErrorHtml
property LastErrorHtml: WideString readonly

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
property LastErrorText: WideString readonly

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
property LastErrorXml: WideString readonly

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
property LastMethodSuccess: Integer

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
LastStringResult
property LastStringResult: WideString readonly

In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. It is accessible only when Chilkat.Global.KeepStringResult is set to TRUE. SQL Server has limitations on string lengths returned from methods and properties, but temp tables can be used to access large strings.

top
LastStringResultLen
property LastStringResultLen: Integer readonly

The length, in characters, of the string contained in the LastStringResult property.

top
NumColumns
property NumColumns: Integer readonly

The number of columns in the first row of the CSV.

When HasColumnNames is 1, the first row is the column-name row, and this property reports the number of column names.

top
NumRows
property NumRows: Integer readonly

The number of data rows in the CSV.

  • When HasColumnNames is 1, the column-name row is not included in the count.
  • Whitespace-only lines following the last non-empty row are not included.

top
UncommonOptions
property UncommonOptions: WideString
Introduced in version 9.5.0.88

Provides optional keywords for uncommon CSV-processing requirements. This property should normally remain empty. To enable more than one option, use a comma-separated list of keywords.

The following keywords are defined:

  • QuotedCells (v9.5.0.96) — Encloses every cell value in double quotation marks when writing the CSV to a file or string.
  • QuotedColumnNames (v9.5.0.96) — Encloses every column name in double quotation marks when writing the CSV to a file or string.
  • EMIT_BOM (v9.5.0.93) — Writes a UTF-8 byte order mark (BOM) when saving the CSV to a UTF-8 encoded file.

top
VerboseLogging
property VerboseLogging: Integer

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
property Version: WideString readonly

Version of the component/library, such as "10.1.0"

More Information and Examples
top
XlsxDateFormat
property XlsxDateFormat: WideString
Introduced in version 11.3.0

Specifies the date format used when converting date cells from an Excel .xlsx worksheet to CSV text.

The default format is mm-dd-yy. Other valid formats include d/m/yyyy, m/d/yyyy, and similar date-format patterns.

top

Methods

DeleteColumn
function DeleteColumn(index: Integer): Integer;

Deletes the column at zero-based index index. The first column is at index 0.

Returns 1 for success, 0 for failure.

More Information and Examples
top
DeleteColumnByName
function DeleteColumnByName(columnName: WideString): Integer;

Deletes the column whose name is specified by columnName.

Returns 1 for success, 0 for failure.

More Information and Examples
top
DeleteRow
function DeleteRow(index: Integer): Integer;

Deletes the entire row at zero-based index index. The first data row is at index 0.

Returns 1 for success, 0 for failure.

More Information and Examples
top
GetCell
function GetCell(row: Integer; col: Integer): WideString;

Returns the contents of the cell at row row and column col.

Row and column indexes are zero-based. The upper-left data cell is at row 0, column 0.

Returns a zero-length WideString on failure

More Information and Examples
top
GetCellByName
function GetCellByName(rowIndex: Integer; columnName: WideString): WideString;

Returns the contents of the cell in row rowIndex and the column named by columnName.

Row indexing begins at 0.

Returns a zero-length WideString on failure

top
GetColumnName
function GetColumnName(index: Integer): WideString;

Returns the name of the column at zero-based index index. The first column is at index 0.

Returns a zero-length WideString on failure

More Information and Examples
top
GetIndex
function GetIndex(columnName: WideString): Integer;

Returns the zero-based index of the column named by columnName.

Returns -1 if no column has the specified name.

top
GetNumCols
function GetNumCols(row: Integer): Integer;

Returns the number of columns in the row at zero-based index row.

Returns 0 if row is beyond the available rows.

top
InsertColumn
function InsertColumn(index: Integer): Integer;
Introduced in version 9.5.0.89

Inserts a new empty column immediately before the column at zero-based index index. The first column is at index 0.

Returns 1 for success, 0 for failure.

More Information and Examples
top
LoadFile
function LoadFile(path: WideString): Integer;

Loads CSV data from the file specified by path.

The file is interpreted using the ANSI character encoding.

Returns 1 for success, 0 for failure.

top
LoadFile2
function LoadFile2(filename: WideString; charset: WideString): Integer;

Loads CSV data from the file specified by filename. charset specifies the character encoding used by the file.

See Supported Charsets for the character-encoding names recognized by Chilkat.

Returns 1 for success, 0 for failure.

More Information and Examples
top
LoadFromString
function LoadFromString(csvData: WideString): Integer;

Loads CSV data from the in-memory string contained in csvData.

Returns 1 for success, 0 for failure.

More Information and Examples
top
RowMatches
function RowMatches(rowIndex: Integer; matchPattern: WideString; caseSensitive: Integer): Integer;

Compares the contents of the row at zero-based index rowIndex with the wildcard pattern in matchPattern.

  • The asterisk character (*) may appear any number of times and matches zero or more characters.
  • When caseSensitive is 1, matching is case-sensitive. When caseSensitive is 0, matching is case-insensitive.

Returns 1 when the row matches the pattern; otherwise returns 0.

top
SaveFile
function SaveFile(path: WideString): Integer;

Writes the CSV to the file specified by path.

The output file is written using the ANSI character encoding.

Returns 1 for success, 0 for failure.

top
SaveFile2
function SaveFile2(filename: WideString; charset: WideString): Integer;

Writes the CSV to the file specified by filename. charset specifies the character encoding to use for the output file. Chilkat converts the CSV text to that encoding while saving.

See Supported Charsets for the character-encoding names recognized by Chilkat.

Returns 1 for success, 0 for failure.

More Information and Examples
top
SaveToSb
function SaveToSb(sb: IChilkatStringBuilder): Integer;
Introduced in version 9.5.0.93

Clears sb and writes the entire CSV document into it.

The record separator is controlled by the Crlf property.

Returns 1 for success, 0 for failure.

top
SaveToString
function SaveToString(): WideString;

Returns the entire CSV document as a string.

The record separator is controlled by the Crlf property.

Returns a zero-length WideString on failure

top
SetCell
function SetCell(row: Integer; col: Integer; content: WideString): Integer;

Sets the cell at row row and column col to the string in content. Row and column indexes are zero-based.

content may contain any characters, including CRLF line endings, double quotation marks, and delimiter characters. When the CSV is saved, Chilkat automatically quotes fields that require quoting. When CSV data is loaded, quoted and escaped fields are parsed automatically.

Returns 1 for success, 0 for failure.

top
SetCellByName
function SetCellByName(rowIndex: Integer; columnName: WideString; contentStr: WideString): Integer;

Sets the cell in row rowIndex and the column named by columnName to the string in contentStr. Row indexing begins at 0.

contentStr may contain delimiter characters, quotation marks, and line endings. Chilkat applies the required CSV quoting when the data is saved.

Returns 1 for success, 0 for failure.

More Information and Examples
top
SetColumnName
function SetColumnName(index: Integer; columnName: WideString): Integer;

Sets the name of the column at zero-based index index to columnName. The first column is at index 0.

Returns 1 for success, 0 for failure.

More Information and Examples
top
SortByColumn
function SortByColumn(columnName: WideString; ascending: Integer; caseSensitive: Integer): Integer;

Sorts the CSV rows using the values in the column named by columnName.

  • When ascending is 1, rows are sorted in ascending order.
  • When ascending is 0, rows are sorted in descending order.
  • When caseSensitive is 1, comparisons are case-sensitive.
  • When caseSensitive is 0, comparisons are case-insensitive.

Returns 1 for success, 0 for failure.

top
SortByColumnIndex
function SortByColumnIndex(index: Integer; ascending: Integer; caseSensitive: Integer): Integer;
Introduced in version 9.5.0.83

Sorts the CSV rows using the values in the column at zero-based index index.

  • When ascending is 1, rows are sorted in ascending order.
  • When ascending is 0, rows are sorted in descending order.
  • When caseSensitive is 1, comparisons are case-sensitive.
  • When caseSensitive is 0, comparisons are case-insensitive.

Returns 1 for success, 0 for failure.

top
XlsxGetSheets
function XlsxGetSheets(xlsx: IChilkatZip; sheetNames: IChilkatStringTable): Integer;
Introduced in version 11.3.0

Gets the names of the worksheets contained in an Excel .xlsx spreadsheet.

  • xlsx is a Zip object containing the already-opened .xlsx file.
  • sheetNames receives the worksheet names.

Returns 1 for success, 0 for failure.

More Information and Examples
top
XlsxLoadSheet
function XlsxLoadSheet(zip: IChilkatZip; sheetName: WideString): Integer;
Introduced in version 11.3.0

Loads a worksheet from an Excel .xlsx spreadsheet into this CSV object.

  • zip is a Zip object containing the already-opened .xlsx file.
  • sheetName is the name of the worksheet to load.
  • To load the first, or default, worksheet, pass an empty string in sheetName.

Returns 1 for success, 0 for failure.

top