CkCsv Java Programming
Reference Documentation

CkCsv

Object Creation

CkCsv obj = new CkCsv();

Properties

// Returns a boolean value
get_Crlf( )

// newVal is a boolean (input)
put_Crlf( newVal )

If true, then CRLF line endings are used when saving the CSV to a file or to a string (i.e. for the methods SaveFile, SaveFile2, SaveToString). If false then bare LF line-endings are used.

// str is a CkString object (output)
get_Delimiter( str )

// newVal is a string (input)
put_Delimiter( newVal )

The character that separates fields in a record. It is a comma by default. If the Delimiter property is not explicitly set, the CSV component will detect the delimiter when loading a CSV. (Semicolons are typically used in locales where the comma is used as a decimal point.)

// Returns a boolean value
get_HasColumnNames( )

// newVal is a boolean (input)
put_HasColumnNames( newVal )

Set to true prior to loading a CSV if the 1st record contains column names. This allows the CSV parser to correctly load the column names and not treat them as data.

// str is a CkString object (output)
LastErrorHtml( str )

To be documented soon.Error information in HTML format for the last method called.

// str is a CkString object (output)
LastErrorText( str )

Error information in plain-text format for the last method called.

// str is a CkString object (output)
LastErrorXml( str )

Error information in XML format for the last method called.

// Returns an integer value
get_NumColumns( )

The number of columns in the 1st row, which may be the row containing column names if HasColumnNames is true.

// Returns an integer value
get_NumRows( )

The number of data rows. If the CSV has column names, the 1st row is not included in the count. Also, empty lines containing only whitespace characters that follow the last non-empty row are not included.

// Returns a boolean value
get_Utf8( )

// b is a boolean (input)
put_Utf8( b )

To be documented soon...

Methods

// row is an integer (input)
// col is an integer (input)
// outStr is a CkString object (output)
// Returns a boolean value
GetCell( row, col, outStr )

Returns the contents of the cell at row, col. Indexing begins at 0. (The topmost/leftmost cell is at 0,0)

Returns true for success, false for failure.

// index is an integer (input)
// outStr is a CkString object (output)
// Returns a boolean value
GetColumnName( index, outStr )

Returns the name of the Nth column.

Returns true for success, false for failure.

// columnName is a string (input)
// Returns an integer value
GetIndex( columnName )

Returns the column index for a given column.

// row is an integer (input)
// Returns an integer value
GetNumCols( row )

Returns the number of columns for a specific row. If the row is larger than the number of rows in the CSV, a zero is returned.

// filename is a string (input)
// Returns a boolean value
LoadFile( filename )

Loads a CSV from a file. It is assumed that the CSV file contains ANSI characters.

Returns true for success, false for failure.

// filename is a string (input)
// charset is a string (input)
// Returns a boolean value
LoadFile2( filename, charset )

Loads a CSV from a file. The charset specifies the character encoding of the CSV file. A list of supported character encodings may be found on this page: Supported Charsets.

Returns true for success, false for failure.

// csvData is a string (input)
// Returns a boolean value
LoadFromString( csvData )

Loads a CSV document from an in-memory string variable.

Returns true for success, false for failure.

// filename is a string (input)
// Returns a boolean value
SaveFile( filename )

Saves a CSV to a file. The output file is written using the ANSI character encoding.

Returns true for success, false for failure.

// filename is a string (input)
// charset is a string (input)
// Returns a boolean value
SaveFile2( filename, charset )

Saves a CSV to a file. The charset specifies the character encoding to use for the CSV file. The text data is converted to this charset when saving. A list of supported character encodings may be found on this page: Supported Charsets.

Returns true for success, false for failure.

// filename is a string (input)
// Returns a boolean value
SaveLastError( filename )

Saves the last error information to an XML formatted file.

// outStr is a CkString object (output)
// Returns a boolean value
SaveToString( outStr )

Writes the entire CSV document to a string variable.

Returns true for success, false for failure.

// row is an integer (input)
// col is an integer (input)
// content is a string (input)
// Returns a boolean value
SetCell( row, col, content )

Sets the contents for a single cell in the CSV. The content may include any characters including CRLF's, double-quotes, and the delimiter character. The Save* methods automatically double-quote fields with special chars when saving. The Load* methods automatically parse double-quoted and/or escaped fields correctly when loading.

// index is an integer (input)
// columnName is a string (input)
// Returns a boolean value
SetColumnName( index, columnName )

Sets the name of the Nth column. The first column is at index 0. This method would only return false if an invalid index is passed (such as a negative number).

Returns true for success, false for failure.

// Returns a string
delimiter( )

The character that separates fields in a record. It is a comma by default. If the Delimiter property is not explicitly set, the CSV component will detect the delimiter when loading a CSV. (Semicolons are typically used in locales where the comma is used as a decimal point.)

// row is an integer (input)
// col is an integer (input)
// Returns a string
getCell( row, col )

Returns the contents of the cell at row, col. Indexing begins at 0. (The topmost/leftmost cell is at 0,0)

// index is an integer (input)
// Returns a string
getColumnName( index )

Returns the name of the Nth column.

// Returns a string
lastErrorHtml( )

Error information in HTML format for the last method called.

// Returns a string
lastErrorText( )

Error information in plain-text format for the last method called.

// Returns a string
lastErrorXml( )

Error information in XML format for the last method called.

// Returns a string
saveToString( )

Writes the entire CSV document to a string variable.