---
product: Chilkat
product_version: 11.7.0
language: tcl
language_label: Tcl
class: Csv
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/tclCsvRef.html
---
# Chilkat Csv — Tcl — v11.7.0

> Chilkat 11.7.0 · language=tcl · class=Csv
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/Csv.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/tcl/guide.md`.

## Purpose

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

For an extended overview, see [Csv Class Overview](https://www.chilkatsoft.com/csv_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```tcl
# 'this' is not a keyword in Tcl. It can freely be used as a variable name.
set this [new CkCsv]
```

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Tcl.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `string # ckStr is a CkString CkCsv_get_DebugLogFilePath $this $ckStr set strVal [CkCsv_get_debugLogFilePath $this] CkCsv_put_DebugLogFilePath $this $strVal` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `string # ckStr is a CkString CkCsv_get_LastErrorHtml $this $ckStr set strVal [CkCsv_get_lastErrorHtml $this]` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `string # ckStr is a CkString CkCsv_get_LastErrorText $this $ckStr set strVal [CkCsv_get_lastErrorText $this]` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `string # ckStr is a CkString CkCsv_get_LastErrorXml $this $ckStr set strVal [CkCsv_get_lastErrorXml $this]` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `boolean 1/0 set boolVal [CkCsv_get_LastMethodSuccess $this] CkCsv_put_LastMethodSuccess $this $boolVal` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `Utf8` | `boolean 1/0 set boolVal [CkCsv_get_Utf8 $this] CkCsv_put_Utf8 $this $boolVal` | read/write | When set to `1`, all `string` arguments and return values are interpreted as UTF-8 strings. |
| `VerboseLogging` | `boolean 1/0 set boolVal [CkCsv_get_VerboseLogging $this] CkCsv_put_VerboseLogging $this $boolVal` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `string # ckStr is a CkString CkCsv_get_Version $this $ckStr set strVal [CkCsv_get_version $this]` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AutoTrim` | property, read/write | `boolean 1/0 set boolVal [CkCsv_get_AutoTrim $this] CkCsv_put_AutoTrim $this $boolVal` |
| `Crlf` | property, read/write | `boolean 1/0 set boolVal [CkCsv_get_Crlf $this] CkCsv_put_Crlf $this $boolVal` |
| `Delimiter` | property, read/write | `string # ckStr is a CkString CkCsv_get_Delimiter $this $ckStr set strVal [CkCsv_get_delimiter $this] CkCsv_put_Delimiter $this $strVal` |
| `EnableQuotes` | property, read/write | `boolean 1/0 set boolVal [CkCsv_get_EnableQuotes $this] CkCsv_put_EnableQuotes $this $boolVal` |
| `EscapeBackslash` | property, read/write | `boolean 1/0 set boolVal [CkCsv_get_EscapeBackslash $this] CkCsv_put_EscapeBackslash $this $boolVal` |
| `HasColumnNames` | property, read/write | `boolean 1/0 set boolVal [CkCsv_get_HasColumnNames $this] CkCsv_put_HasColumnNames $this $boolVal` |
| `NumColumns` | property, read-only | `integer set intVal [CkCsv_get_NumColumns $this]` |
| `NumRows` | property, read-only | `integer set intVal [CkCsv_get_NumRows $this]` |
| `UncommonOptions` | property, read/write | `string # ckStr is a CkString CkCsv_get_UncommonOptions $this $ckStr set strVal [CkCsv_get_uncommonOptions $this] CkCsv_put_UncommonOptions $this $strVal` |
| `XlsxDateFormat` | property, read/write | `string # ckStr is a CkString CkCsv_get_XlsxDateFormat $this $ckStr set strVal [CkCsv_get_xlsxDateFormat $this] CkCsv_put_XlsxDateFormat $this $strVal` |
| `DeleteColumn` | method | `# index is an integer set status [CkCsv_DeleteColumn $this $index]` |
| `DeleteColumnByName` | method | `# columnName is a string set status [CkCsv_DeleteColumnByName $this $columnName]` |
| `DeleteRow` | method | `# index is an integer set status [CkCsv_DeleteRow $this $index]` |
| `GetCell` | method | `# row is an integer # col is an integer # outStr is a CkString (output) set status [CkCsv_GetCell $this $row $col $outStr] set retStr [CkCsv_getCell $this $row $col]` |
| `GetCellByName` | method | `# rowIndex is an integer # columnName is a string # outStr is a CkString (output) set status [CkCsv_GetCellByName $this $rowIndex $columnName $outStr] set retStr [CkCsv_getCellByName $this $rowIndex $columnName]` |
| `GetColumnName` | method | `# index is an integer # outStr is a CkString (output) set status [CkCsv_GetColumnName $this $index $outStr] set retStr [CkCsv_getColumnName $this $index]` |
| `GetIndex` | method | `# columnName is a string set retInt [CkCsv_GetIndex $this $columnName]` |
| `GetNumCols` | method | `# row is an integer set retInt [CkCsv_GetNumCols $this $row]` |
| `InsertColumn` | method | `# index is an integer set status [CkCsv_InsertColumn $this $index]` |
| `LoadFile` | method | `# path is a string set status [CkCsv_LoadFile $this $path]` |
| `LoadFile2` | method | `# filename is a string # charset is a string set status [CkCsv_LoadFile2 $this $filename $charset]` |
| `LoadFromString` | method | `# csvData is a string set status [CkCsv_LoadFromString $this $csvData]` |
| `RowMatches` | method | `# rowIndex is an integer # matchPattern is a string # caseSensitive is a boolean set retBool [CkCsv_RowMatches $this $rowIndex $matchPattern $caseSensitive]` |
| `SaveFile` | method | `# path is a string set status [CkCsv_SaveFile $this $path]` |
| `SaveFile2` | method | `# filename is a string # charset is a string set status [CkCsv_SaveFile2 $this $filename $charset]` |
| `SaveToSb` | method | `# sb is a CkStringBuilder set status [CkCsv_SaveToSb $this $sb]` |
| `SaveToString` | method | `# outStr is a CkString (output) set status [CkCsv_SaveToString $this $outStr] set retStr [CkCsv_saveToString $this]` |
| `SetCell` | method | `# row is an integer # col is an integer # content is a string set status [CkCsv_SetCell $this $row $col $content]` |
| `SetCellByName` | method | `# rowIndex is an integer # columnName is a string # contentStr is a string set status [CkCsv_SetCellByName $this $rowIndex $columnName $contentStr]` |
| `SetColumnName` | method | `# index is an integer # columnName is a string set status [CkCsv_SetColumnName $this $index $columnName]` |
| `SortByColumn` | method | `# columnName is a string # ascending is a boolean # caseSensitive is a boolean set status [CkCsv_SortByColumn $this $columnName $ascending $caseSensitive]` |
| `SortByColumnIndex` | method | `# index is an integer # ascending is a boolean # caseSensitive is a boolean set status [CkCsv_SortByColumnIndex $this $index $ascending $caseSensitive]` |
| `XlsxGetSheets` | method | `# xlsx is a CkZip # sheetNames is a CkStringTable set status [CkCsv_XlsxGetSheets $this $xlsx $sheetNames]` |
| `XlsxLoadSheet` | method | `# zip is a CkZip # sheetName is a string set status [CkCsv_XlsxLoadSheet $this $zip $sheetName]` |

## Properties

### Csv.AutoTrim

`Chilkat 11.7.0 · tcl · Csv · AutoTrim · property · read/write`

```tcl
boolean 1/0
set boolVal [CkCsv_get_AutoTrim $this]

CkCsv_put_AutoTrim $this $boolVal
```

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

- When `1`, surrounding whitespace such as spaces and tabs is removed from returned cell values.
- When `0`, returned cell values are not trimmed. This is the default.

This property does not modify the cell contents stored in the CSV and does not change the text written by the save methods. It also does not trim the names returned by `GetColumnName`.

### Csv.Crlf

`Chilkat 11.7.0 · tcl · Csv · Crlf · property · read/write`

```tcl
boolean 1/0
set boolVal [CkCsv_get_Crlf $this]

CkCsv_put_Crlf $this $boolVal
```

Controls the line endings used by `SaveFile`, `SaveFile2`, `SaveToString`, and `SaveToSb`.

- When `1`, records are terminated with CRLF. This is the default.
- When `0`, records are terminated with LF.

The original line-ending style of loaded data is not preserved. The selected line ending is used for all output records, including the final record.

### Csv.Delimiter

`Chilkat 11.7.0 · tcl · Csv · Delimiter · property · read/write`

```tcl
string
# ckStr is a CkString

CkCsv_get_Delimiter $this $ckStr

set strVal [CkCsv_get_delimiter $this]

CkCsv_put_Delimiter $this $strVal
```

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

Although this property has a string type, only the first character of a non-empty value is used. Assigning an empty string does not clear or reset the current delimiter.

If the delimiter has not been explicitly set, Chilkat detects it while loading the first CSV data and updates this property with the detected character. The detection may examine more than the first record. Once selected or detected, the delimiter remains in effect for subsequent loads performed by the same object. To load data that uses a different delimiter, explicitly set this property before loading or use a new `Csv` object.

A semicolon (`;`) is commonly used in locales where a comma is used as the decimal separator.

**Creating a new CSV:** Set this property before adding rows or columns when a delimiter other than comma is required.

**Vertical-bar delimiter:** If this property is explicitly set to `|`, and `EnableQuotes` has not been explicitly set, `EnableQuotes` defaults to `0`.

### Csv.EnableQuotes

`Chilkat 11.7.0 · tcl · Csv · EnableQuotes · property · read/write · since 9.5.0.71`

```tcl
boolean 1/0
set boolVal [CkCsv_get_EnableQuotes $this]

CkCsv_put_EnableQuotes $this $boolVal
```

Controls whether double quotation marks have their standard CSV meaning when reading and writing data. The default value is `1`.

When `1`, a quoted field is treated as one field even when it contains the delimiter, CR, or LF. A double quotation mark inside a quoted field is represented by two consecutive double quotation marks. Fields created by the application are quoted automatically when required.

Chilkat retains whether a field loaded from CSV text was quoted, so quotation marks that were not strictly required may remain when the CSV is saved again.

When `0`, quotation marks are ordinary characters and do not protect delimiters or line endings. Do not disable quoting when field values can contain the delimiter, quotation marks, CR, or LF, because such values cannot be represented or round-tripped reliably as ordinary delimited text.

### Csv.EscapeBackslash

`Chilkat 11.7.0 · tcl · Csv · EscapeBackslash · property · read/write · since 9.5.0.44`

```tcl
boolean 1/0
set boolVal [CkCsv_get_EscapeBackslash $this]

CkCsv_put_EscapeBackslash $this $boolVal
```

Controls whether a backslash causes the following character to be treated literally while parsing CSV data. The default value is `0`.

When `1`, examples include:

- `\,` represents a literal delimiter character.
- `\\` represents one backslash.
- `\"` represents a literal double quotation mark.

This is not C-style escape decoding. For example, `\n`, `\r`, and `\t` produce the literal characters `n`, `r`, and `t`; they do not produce a line feed, carriage return, or tab.

Normal CSV quoting is still used when output fields contain delimiters or line endings.

### Csv.HasColumnNames

`Chilkat 11.7.0 · tcl · Csv · HasColumnNames · property · read/write`

```tcl
boolean 1/0
set boolVal [CkCsv_get_HasColumnNames $this]

CkCsv_put_HasColumnNames $this $boolVal
```

Indicates whether the first record is a column-name row rather than a data row. The default value is `0`.

Set this property to `1` **before** loading CSV data when the first record contains column names. Chilkat then stores the first record as the column names and excludes it from `NumRows` and zero-based data-row indexing.

Changing this property to `1` after data has already been loaded does not reinterpret the first data row as column names. Calling `SetColumnName` automatically changes this property to `1`.

Methods that address a column by name require this property to be `1` and require the requested name to exist.

### Csv.NumColumns

`Chilkat 11.7.0 · tcl · Csv · NumColumns · property · read-only`

```tcl
integer
set intVal [CkCsv_get_NumColumns $this]
```

The number of columns in the first row of the CSV. When `HasColumnNames` is `1`, this is the number of column names in the header row.

CSV rows may contain different numbers of fields. Therefore, this property is not necessarily the maximum number of columns found in any row. Use `GetNumCols` to obtain the number of columns in a particular data row.

### Csv.NumRows

`Chilkat 11.7.0 · tcl · Csv · NumRows · property · read-only`

```tcl
integer
set intVal [CkCsv_get_NumRows $this]
```

The number of data rows in the CSV.

- When `HasColumnNames` is `1`, the column-name row is not included.
- Interior blank rows are included.
- Empty or whitespace-only rows following the last non-empty row are not included.

### Csv.UncommonOptions

`Chilkat 11.7.0 · tcl · Csv · UncommonOptions · property · read/write · since 9.5.0.88`

```tcl
string
# ckStr is a CkString

CkCsv_get_UncommonOptions $this $ckStr

set strVal [CkCsv_get_uncommonOptions $this]

CkCsv_put_UncommonOptions $this $strVal
```

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.

The following keywords are defined:

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

### Csv.XlsxDateFormat

`Chilkat 11.7.0 · tcl · Csv · XlsxDateFormat · property · read/write · since 11.3.0`

```tcl
string
# ckStr is a CkString

CkCsv_get_XlsxDateFormat $this $ckStr

set strVal [CkCsv_get_xlsxDateFormat $this]

CkCsv_put_XlsxDateFormat $this $strVal
```

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

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

## Methods

### Csv.DeleteColumn

`Chilkat 11.7.0 · tcl · Csv · DeleteColumn · method`

```tcl
# index is an integer

set status [CkCsv_DeleteColumn $this $index]
```

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.

`index` must not be negative. For predictable deletion, `index` should be less than `NumColumns`.

Returns 1 for success, 0 for failure.

### Csv.DeleteColumnByName

`Chilkat 11.7.0 · tcl · Csv · DeleteColumnByName · method`

```tcl
# columnName is a string

set status [CkCsv_DeleteColumnByName $this $columnName]
```

Deletes the column named by `columnName`. This method requires `HasColumnNames` to be `1`.

Column-name matching is case-sensitive. Surrounding whitespace in a loaded column name is not part of its lookup name. Column names should be unique to avoid ambiguous lookup and deletion behavior.

Returns 1 for success, 0 for failure.

### Csv.DeleteRow

`Chilkat 11.7.0 · tcl · Csv · DeleteRow · method`

```tcl
# index is an integer

set status [CkCsv_DeleteRow $this $index]
```

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.

`index` must be between `0` and `NumRows - 1`.

Returns 1 for success, 0 for failure.

### Csv.GetCell

`Chilkat 11.7.0 · tcl · Csv · GetCell · method`

```tcl
# row is an integer

# col is an integer

# outStr is a CkString (output)

set status [CkCsv_GetCell $this $row  $col $outStr]

set retStr [CkCsv_getCell $this $row $col]
```

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

Row and column indexes are zero-based. The upper-left data cell is at row `0`, column `0`. When `HasColumnNames` is `1`, the header row is not included in the row index.

- If `row` is negative or beyond the available data rows, `NULL` is returned and `LastMethodSuccess` is `0`.
- If `col` is negative, `NULL` is returned and `LastMethodSuccess` is `0`.
- If `row` is valid but `col` is beyond the number of fields in that row, an empty string is returned and `LastMethodSuccess` is `1`.

When `AutoTrim` is `1`, surrounding whitespace is removed from the returned value without changing the stored cell content.

Returns 1 for success, 0 for failure.

### Csv.GetCellByName

`Chilkat 11.7.0 · tcl · Csv · GetCellByName · method`

```tcl
# rowIndex is an integer

# columnName is a string

# outStr is a CkString (output)

set status [CkCsv_GetCellByName $this $rowIndex  $columnName $outStr]

set retStr [CkCsv_getCellByName $this $rowIndex $columnName]
```

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.

This method requires `HasColumnNames` to be `1`. Column-name matching is case-sensitive. Surrounding whitespace is removed from column names for lookup purposes, so `columnName` should contain the trimmed name. If duplicate lookup names exist, the last matching column is used.

If the row or column name is invalid, `NULL` is returned and `LastMethodSuccess` is `0`. When `AutoTrim` is `1`, surrounding whitespace is removed from the returned cell value.

Returns 1 for success, 0 for failure.

### Csv.GetColumnName

`Chilkat 11.7.0 · tcl · Csv · GetColumnName · method`

```tcl
# index is an integer

# outStr is a CkString (output)

set status [CkCsv_GetColumnName $this $index $outStr]

set retStr [CkCsv_getColumnName $this $index]
```

Returns the original, untrimmed name of the column at zero-based index `index`. The first column is at index `0`.

Returns 1 for success, 0 for failure.

### Csv.GetIndex

`Chilkat 11.7.0 · tcl · Csv · GetIndex · method`

```tcl
# columnName is a string

set retInt [CkCsv_GetIndex $this $columnName]
```

Returns the zero-based index of the column named by `columnName`, or `-1` if no matching column exists.

This method requires `HasColumnNames` to be `1`. Matching is case-sensitive. Surrounding whitespace is removed from loaded column names for lookup purposes, so `columnName` should contain the trimmed name. If duplicate lookup names exist, the index of the last matching column is returned.

### Csv.GetNumCols

`Chilkat 11.7.0 · tcl · Csv · GetNumCols · method`

```tcl
# row is an integer

set retInt [CkCsv_GetNumCols $this $row]
```

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.

Returns `0` if `row` is negative or beyond the available data rows.

### Csv.InsertColumn

`Chilkat 11.7.0 · tcl · Csv · InsertColumn · method · since 9.5.0.89`

```tcl
# index is an integer

set status [CkCsv_InsertColumn $this $index]
```

Inserts one empty field into each existing row and, when present, into the column-name row. `index` is a zero-based insertion position.

- If `index` is within a row, the empty field is inserted before that position.
- If `index` is at or beyond the end of a row, one empty field is appended to that row.
- Rows are not padded to a common width, so ragged rows remain ragged.
- Calling this method on an object with no rows and no column-name row has no effect.

`index` must not be negative.

Returns 1 for success, 0 for failure.

### Csv.LoadFile

`Chilkat 11.7.0 · tcl · Csv · LoadFile · method`

```tcl
# path is a string

set status [CkCsv_LoadFile $this $path]
```

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.

On Windows, the file is decoded using the current Windows ANSI code page. Use `LoadFile2` when the character encoding must be specified explicitly.

The existing CSV contents are cleared before the file is opened. Therefore, a failure such as a missing file does not preserve the previously loaded data.

Returns 1 for success, 0 for failure.

### Csv.LoadFile2

`Chilkat 11.7.0 · tcl · Csv · LoadFile2 · method`

```tcl
# filename is a string

# charset is a string

set status [CkCsv_LoadFile2 $this $filename  $charset]
```

Clears the current contents and loads CSV data from the file specified by `filename`. `charset` specifies the character encoding used by the file.

Set `HasColumnNames`, `Delimiter`, `EnableQuotes`, and other parsing options before calling this method.

See [Supported Charsets](https://www.chilkatsoft.com/charsets_supported_by_chilkat.asp) for the encoding names recognized by Chilkat.

Returns 1 for success, 0 for failure.

### Csv.LoadFromString

`Chilkat 11.7.0 · tcl · Csv · LoadFromString · method`

```tcl
# csvData is a string

set status [CkCsv_LoadFromString $this $csvData]
```

Clears the current contents and loads the CSV text contained in `csvData`. Set `HasColumnNames`, `Delimiter`, `EnableQuotes`, and other parsing options before calling this method.

Passing an empty string successfully clears the CSV. The parser is permissive; for example, an unterminated quoted field extends through the end of `csvData` rather than necessarily causing the load to fail.

Returns 1 for success, 0 for failure.

### Csv.RowMatches

`Chilkat 11.7.0 · tcl · Csv · RowMatches · method`

```tcl
# rowIndex is an integer

# matchPattern is a string

# caseSensitive is a boolean

set retBool [CkCsv_RowMatches $this $rowIndex  $matchPattern  $caseSensitive]
```

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.

- 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.
- `AutoTrim` does not alter the row used for matching.

Returns `1` when the row matches `matchPattern`. Returns `0` when it does not match or when `rowIndex` is outside the available data rows.

### Csv.SaveFile

`Chilkat 11.7.0 · tcl · Csv · SaveFile · method`

```tcl
# path is a string

set status [CkCsv_SaveFile $this $path]
```

Writes the entire CSV to the file specified by `path`.

On Windows, the text is encoded using the current Windows ANSI code page. Use `SaveFile2` when the output encoding must be specified explicitly.

Record endings are controlled by `Crlf`, and the final record is also followed by the selected line ending.

Returns 1 for success, 0 for failure.

### Csv.SaveFile2

`Chilkat 11.7.0 · tcl · Csv · SaveFile2 · method`

```tcl
# filename is a string

# charset is a string

set status [CkCsv_SaveFile2 $this $filename  $charset]
```

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.

Record endings are controlled by `Crlf`, and the final record is also followed by the selected line ending.

See [Supported Charsets](https://www.chilkatsoft.com/charsets_supported_by_chilkat.asp) for the encoding names recognized by Chilkat.

Returns 1 for success, 0 for failure.

### Csv.SaveToSb

`Chilkat 11.7.0 · tcl · Csv · SaveToSb · method · since 9.5.0.93`

```tcl
# sb is a CkStringBuilder

set status [CkCsv_SaveToSb $this $sb]
```

Clears `sb` and writes the entire CSV document into it.

Record endings are controlled by `Crlf`. `sb` contains a line ending after the final record.

Returns 1 for success, 0 for failure.

### Csv.SaveToString

`Chilkat 11.7.0 · tcl · Csv · SaveToString · method`

```tcl
# outStr is a CkString (output)

set status [CkCsv_SaveToString $this $outStr]

set retStr [CkCsv_saveToString $this]
```

Returns the entire CSV document as a string.

Record endings are controlled by `Crlf`. The returned string includes a line ending after the final record. The line-ending style originally loaded into the object is not preserved.

Returns 1 for success, 0 for failure.

### Csv.SetCell

`Chilkat 11.7.0 · tcl · Csv · SetCell · method`

```tcl
# row is an integer

# col is an integer

# content is a string

set status [CkCsv_SetCell $this $row  $col  $content]
```

Sets the cell at zero-based data row `row` and column `col` to `content`.

The CSV grows as needed. If `row` is beyond the current last row, intervening rows are created as empty rows. Within the target row, intervening columns are created as empty cells. Other rows are not padded, so the resulting CSV may contain rows with different numbers of fields. Passing `NumRows` as `row` appends a new data row.

`content` may contain delimiters, quotation marks, CR, and LF when `EnableQuotes` is `1`; Chilkat applies the necessary CSV quoting when the data is saved. `row` and `col` must not be negative.

Returns 1 for success, 0 for failure.

### Csv.SetCellByName

`Chilkat 11.7.0 · tcl · Csv · SetCellByName · method`

```tcl
# rowIndex is an integer

# columnName is a string

# contentStr is a string

set status [CkCsv_SetCellByName $this $rowIndex  $columnName  $contentStr]
```

Sets the cell at zero-based data row `rowIndex` in the column named by `columnName` to `contentStr`.

This method requires `HasColumnNames` to be `1` and requires `columnName` to match an existing column name. Matching is case-sensitive and uses the trimmed lookup form of the stored column name. A missing column is not created.

The data-row collection grows as needed. `contentStr` may contain delimiters, quotation marks, CR, and LF when `EnableQuotes` is `1`.

Returns 1 for success, 0 for failure.

### Csv.SetColumnName

`Chilkat 11.7.0 · tcl · Csv · SetColumnName · method`

```tcl
# index is an integer

# columnName is a string

set status [CkCsv_SetColumnName $this $index  $columnName]
```

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

Calling this method automatically sets `HasColumnNames` to `1`. It can therefore be used on an empty object to create the column-name row. `index` must not be negative.

For reliable name-based access, use unique column names without surrounding whitespace.

Returns 1 for success, 0 for failure.

### Csv.SortByColumn

`Chilkat 11.7.0 · tcl · Csv · SortByColumn · method`

```tcl
# columnName is a string

# ascending is a boolean

# caseSensitive is a boolean

set status [CkCsv_SortByColumn $this $columnName  $ascending  $caseSensitive]
```

Sorts the data rows using the values in the column named by `columnName`. The column-name row is not moved.

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

Values are compared as strings, not as numbers or dates. For example, ascending order places `10` before `2`. Empty or missing sort cells appear first in ascending order and last in descending order. The sort is not stable, so rows having equal sort values may change relative order.

This method requires `HasColumnNames` to be `1` and `columnName` to name an existing column.

Returns 1 for success, 0 for failure.

### Csv.SortByColumnIndex

`Chilkat 11.7.0 · tcl · Csv · SortByColumnIndex · method · since 9.5.0.83`

```tcl
# index is an integer

# ascending is a boolean

# caseSensitive is a boolean

set status [CkCsv_SortByColumnIndex $this $index  $ascending  $caseSensitive]
```

Sorts the data rows using the values in the column at zero-based index `index`. The column-name row, when present, is not moved.

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

Values are compared as strings, not as numbers or dates. Empty and missing sort cells are treated as empty strings. They appear first in ascending order and last in descending order. The sort is not stable, so rows having equal sort values may change relative order.

Returns 1 for success, 0 for failure.

### Csv.XlsxGetSheets

`Chilkat 11.7.0 · tcl · Csv · XlsxGetSheets · method · since 11.3.0`

```tcl
# xlsx is a CkZip

# sheetNames is a CkStringTable

set status [CkCsv_XlsxGetSheets $this $xlsx  $sheetNames]
```

Gets the worksheet names contained in an Excel `.xlsx` workbook.

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

Returns 1 for success, 0 for failure.

### Csv.XlsxLoadSheet

`Chilkat 11.7.0 · tcl · Csv · XlsxLoadSheet · method · since 11.3.0`

```tcl
# zip is a CkZip

# sheetName is a string

set status [CkCsv_XlsxLoadSheet $this $zip  $sheetName]
```

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

- `zip` is a `Zip` object containing the already-opened `.xlsx` file.
- `sheetName` is the worksheet name.
- Pass an empty string in `sheetName` to load the workbook's default worksheet.

The `XlsxDateFormat` property controls the text format used for Excel date cells.

Returns 1 for success, 0 for failure.

## Related classes

[`StringBuilder`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/tcl/classes/StringBuilder.md), [`StringTable`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/tcl/classes/StringTable.md), [`Zip`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/tcl/classes/Zip.md)

