CkCsv class final

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

CkCsv 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.

For an extended overview, see Csv Class Overview.

A CkCsv owns a native Chilkat object. It is released automatically when the Dart object is garbage collected, or immediately by dispose. Use it only from the isolate that created it.

Implemented types

Constructors

CkCsv()
Creates a new CkCsv object.

Properties

autoTrim ↔ bool
Controls whether leading and trailing whitespace is removed from values returned by GetCell and GetCellByName.
getter/setter pair
crlf ↔ bool
Controls the line endings used by SaveFile, SaveFile2, SaveToString, and SaveToSb.
getter/setter pair
debugLogFilePath ↔ String
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.
getter/setter pair
delimiter ↔ String
Specifies the single character used to separate fields within each CSV record. The default value is a comma (,).
getter/setter pair
enableQuotes ↔ bool
Controls whether double quotation marks have their standard CSV meaning when reading and writing data. The default value is true.
getter/setter pair
escapeBackslash ↔ bool
Controls whether a backslash causes the following character to be treated literally while parsing CSV data. The default value is false.
getter/setter pair
hasColumnNames ↔ bool
Indicates whether the first record is a column-name row rather than a data row. The default value is false.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether dispose has been called on this object.
no setter
lastErrorHtml → String
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.
no setter
lastErrorText → String
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.
no setter
lastErrorXml → String
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.
no setter
lastMethodSuccess ↔ bool
Indicates the success or failure of the most recent method call: true means success, false 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.
getter/setter pair
numColumns → int
The number of columns in the first row of the CSV. When HasColumnNames is true, this is the number of column names in the header row.
no setter
numRows → int
The number of data rows in the CSV.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
uncommonOptions ↔ String
Provides optional keywords for uncommon CSV-processing requirements. The default value is an empty string, and this property should normally remain empty. To enable more than one option, use a comma-separated list.
getter/setter pair
verboseLogging ↔ bool
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
getter/setter pair
version → String
Version of the component/library, such as "10.1.0"
no setter
xlsxDateFormat ↔ String
Specifies the date format used when converting Excel date cells from an .xlsx worksheet to CSV text.
getter/setter pair

Methods

deleteColumn(int index) → void
Deletes the column at zero-based index index. The deletion is applied to the column-name row, when present, and to each data row that contains that column.
deleteColumnByName(String columnName) → void
Deletes the column named by columnName. This method requires HasColumnNames to be true.
deleteRow(int index) → void
Deletes the data row at zero-based index index. The first data row is at index 0, regardless of whether a column-name row exists.
dispose() → void
Releases the native object now instead of waiting for garbage collection.
getCell(int row, int col) → String
Returns the contents of the cell at data row row and column col.
getCellByName(int rowIndex, String columnName) → String
Returns the contents of the cell at data row rowIndex in the column named by columnName. Row indexing begins at 0 and excludes the header row.
getColumnName(int index) → String
Returns the original, untrimmed name of the column at zero-based index index. The first column is at index 0.
getIndex(String columnName) → int
Returns the zero-based index of the column named by columnName, or -1 if no matching column exists.
getNumCols(int row) → int
Returns the number of fields in the data row at zero-based index row. This is useful for CSV data containing rows of different lengths.
insertColumn(int index) → void
Inserts one empty field into each existing row and, when present, into the column-name row. index is a zero-based insertion position.
loadFile(String path) → void
Clears the current contents and loads CSV data from the file specified by path. Set HasColumnNames, Delimiter, EnableQuotes, and other parsing options before calling this method.
loadFile2(String filename, String charset) → void
Clears the current contents and loads CSV data from the file specified by filename. charset specifies the character encoding used by the file.
loadFromString(String csvData) → void
Clears the current contents and loads the CSV text contained in csvData. Set HasColumnNames, Delimiter, EnableQuotes, and other parsing options before calling this method.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rowMatches(int rowIndex, String matchPattern, bool caseSensitive) → bool
Compares the complete data row at zero-based index rowIndex with the wildcard pattern in matchPattern. The row is compared as one delimited record using the current Delimiter; the pattern may therefore include or span field separators.
saveFile(String path) → void
Writes the entire CSV to the file specified by path.
saveFile2(String filename, String charset) → void
Writes the entire CSV to the file specified by filename. charset specifies the output character encoding, and Chilkat converts the CSV text to that encoding while saving.
saveToSb(CkStringBuilder sb) → void
Clears sb and writes the entire CSV document into it.
saveToString() → String
Returns the entire CSV document as a string.
setCell(int row, int col, String content) → void
Sets the cell at zero-based data row row and column col to content.
setCellByName(int rowIndex, String columnName, String contentStr) → void
Sets the cell at zero-based data row rowIndex in the column named by columnName to contentStr.
setColumnName(int index, String columnName) → void
Sets the name of the column at zero-based index index to columnName. The first column is at index 0.
sortByColumn(String columnName, bool ascending, bool caseSensitive) → void
Sorts the data rows using the values in the column named by columnName. The column-name row is not moved.
sortByColumnIndex(int index, bool ascending, bool caseSensitive) → void
Sorts the data rows using the values in the column at zero-based index index. The column-name row, when present, is not moved.
toString() → String
A string representation of this object.
override
xlsxGetSheets(CkZip xlsx, CkStringTable sheetNames) → void
Gets the worksheet names contained in an Excel .xlsx workbook.
xlsxLoadSheet(CkZip zip, String sheetName) → void
Loads a worksheet from an Excel .xlsx workbook into this CSV object.

Operators

operator ==(Object other) → bool
The equality operator.
inherited