Click or drag to resize

FileCsvDocument Class

A simple, general-purpose, in-memory representation of a RFC 4180-compliant comma-separated value (CSV) file.

Read a file with Read(String) (or Read(String, Boolean) to treat the first row as a column-name header), then query its dimensions (RowCount, ColumnCount), retrieve typed values by column and row with the TryGet methods — addressing columns by index or, when a header is present, by name — or enumerate its rows. To build a file, construct the document with a fixed column count, populate cells with the Set(Int32, Int32, String) overloads (addressed by column and row), then persist it with Save(String). Every row has the same number of columns; addressing a column outside that count throws.

Inheritance Hierarchy
SystemObject
  Rhino.FileIOFileCsvDocument

Namespace:  Rhino.FileIO
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 9.0
Syntax
public class FileCsvDocument : IEnumerable<string[]>, 
	IEnumerable

The FileCsvDocument type exposes the following members.

Constructors
  NameDescription
Public methodFileCsvDocument(Int32)
Constructs a new, empty document with a fixed number of columns. Every row written to the document has exactly this many fields. The document has no header row.
Public methodFileCsvDocument(String)
Constructs a new, empty document with a header row of column names. The number of columns is the number of names supplied, and the header is written ahead of the data rows by Save(String). Columns can then be addressed by name (see ColumnIndex(String) and the name-keyed TryGet overloads).
Top
Properties
  NameDescription
Public propertyColumnCount
The number of columns in the document. Every row has exactly this many fields.
Public propertyHasHeader
True if the document has a header row of column names. See ColumnIndex(String).
Public propertyHeader
The column names, or null if the document has no header. RowCount counts only the data rows; the header is not one of them.
Public propertyItem
Gets the value of a cell, addressed by column and row. Use TryGetString(Int32, Int32, String) for access that does not throw when the cell does not exist.
Public propertyRowCount
The number of rows in the document.
Top
Methods
  NameDescription
Public methodClear
Removes all rows from the document.
Public methodColumnIndex
Returns the zero-based index of the column with the given name (case-insensitive), or -1 if the document has no header or no column with that name. When names are duplicated, the first is returned.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates over the committed rows of the document.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRow
Returns the fields of a row.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberRead(String)
Reads a CSV file from disk. The file is assumed to have no header row.
Public methodStatic memberRead(TextReader)
Reads CSV content from a text reader. The content is assumed to have no header row.
Public methodStatic memberRead(String, Boolean)
Reads a CSV file from disk.
Public methodStatic memberRead(TextReader, Boolean)
Reads CSV content from a text reader.
Public methodSave(String)
Writes the document to a file on disk, encoded as UTF-8 with a byte order mark. The mark lets spreadsheet applications (for example Excel on Windows and Mac) detect the encoding rather than falling back to the system code page, which garbles non-ASCII text such as Korean (RH-97173). Use Save(String, Encoding) with new UTF8Encoding(false) to write UTF-8 without a mark.
Public methodSave(TextWriter)
Writes the document to a text writer. Records are separated by CRLF, per RFC 4180. If the document has a header, it is written ahead of the data rows.
Public methodSave(String, Encoding)
Writes the document to a file on disk using the specified encoding.
Public methodSet(Int32, Point3d)
Sets a row from a 3-D point. This is only valid when ColumnCount is 3: the point's X, Y, and Z are written to columns 0, 1, and 2 with the general ("G") format specifier and the invariant culture.
Public methodSet(Int32, Point3d, String)
Sets a row from a 3-D point, using the specified .NET numeric format string. This is only valid when ColumnCount is 3: the point's X, Y, and Z are written to columns 0, 1, and 2 with the invariant culture.
Public methodSet(Int32, Int32, Boolean)
Sets the value of a cell to a boolean, written as "1" (true) or "0" (false).
Public methodSet(Int32, Int32, DateTime)
Sets the value of a cell to a date and time, formatted as a round-trip ISO 8601 string (the "o" format) using the invariant culture.
Public methodSet(Int32, Int32, Double)
Sets the value of a specific cell to a double-precision number, formatted with the general ("G") format specifier and the invariant culture.
Public methodSet(Int32, Int32, Color)
Sets the value of a cell to a color, stored as its 32-bit ARGB integer (ToArgb), so that the alpha channel round-trips.
Public methodSet(Int32, Int32, Guid)
Sets the value of a cell to a globally unique identifier, formatted with hyphens and no braces (the "D" format, for example "11f820ff-952a-4b0b-b10a-59f82c2eb1f4").
Public methodSet(Int32, Int32, Int32)
Sets the value of a specific cell to a 32-bit integer, formatted using the invariant culture.
Public methodSet(Int32, Int32, Int64)
Sets the value of a specific cell to a 64-bit integer, formatted using the invariant culture.
Public methodSet(Int32, Int32, String)
Sets the value of a cell, addressed by column and row. Rows are added as needed (any intervening rows are created and filled with empty fields), but the column count is fixed.
Public methodSet(Int32, Int32, DateTime, String)
Sets the value of a cell to a date and time, formatted with the specified .NET date/time format string and the invariant culture.
Public methodSet(Int32, Int32, Double, String)
Sets the value of a specific cell to a double-precision number, formatted with the specified .NET numeric format string and the invariant culture.
Public methodSet(Int32, Int32, Double, LengthUnit, DistanceDisplayMode, Int32)
Sets the value of a cell to a double-precision number, formatted with FormatNumber(Double, LengthUnit, DistanceDisplayMode, Int32, Boolean). The unit system name is never appended to the field.
Public methodSet(Int32, Int32, Double, UnitSystem, DistanceDisplayMode, Int32)
Sets the value of a cell to a double-precision number, formatted with FormatNumber(Double, UnitSystem, DistanceDisplayMode, Int32, Boolean). The unit system name is never appended to the field.
Public methodSetRow(Int32, IEnumerableString)
Sets the fields of a row, addressed by index, growing the document as needed (any intervening rows are created and filled with empty fields). This is the row-level counterpart to GetRow(Int32). The number of fields must equal ColumnCount. A null field is stored as an empty field.
Public methodSetRow(Int32, String)
Sets the fields of a row, addressed by index, growing the document as needed (any intervening rows are created and filled with empty fields). This is the row-level counterpart to GetRow(Int32). The number of fields must equal ColumnCount. A null field is stored as an empty field.
Public methodToString
Returns the full CSV content of the document as a string.
(Overrides ObjectToString.)
Public methodTryGetBool(Int32, Int32, Boolean)
Retrieves the value of a cell as a boolean. Recognizes "true"/"false", "yes"/"no", and "1"/"0" (case-insensitive, surrounding whitespace ignored).
Public methodTryGetBool(String, Int32, Boolean)
Retrieves the value of a cell as a boolean, addressing the column by header name.
Public methodTryGetColor(Int32, Int32, Color)
Retrieves the value of a cell as a color from its 32-bit ARGB integer (FromArgb(Int32)), as written by Set(Int32, Int32, Color).
Public methodTryGetColor(String, Int32, Color)
Retrieves the value of a cell as a color, addressing the column by header name.
Public methodTryGetDateTime(Int32, Int32, DateTime)
Retrieves the value of a cell as a date and time, parsed with the invariant culture and RoundtripKind (so ISO 8601 values, including those written by Set(Int32, Int32, DateTime), round-trip).
Public methodTryGetDateTime(String, Int32, DateTime)
Retrieves the value of a cell as a date and time, addressing the column by header name.
Public methodTryGetDouble(Int32, Int32, Double)
Retrieves the value of a cell as a double-precision number. The cell is evaluated with TryParseNumber(String, Double), so command-line math expressions (for example "1/2") are supported.
Public methodTryGetDouble(String, Int32, Double)
Retrieves the value of a cell as a double-precision number, addressing the column by header name.
Public methodTryGetGuid(Int32, Int32, Guid)
Retrieves the value of a cell as a globally unique identifier. Accepts any of the formats understood by TryParse(String, Guid) (with or without hyphens or braces).
Public methodTryGetGuid(String, Int32, Guid)
Retrieves the value of a cell as a globally unique identifier, addressing the column by header name.
Public methodTryGetInt(Int32, Int32, Int32)
Retrieves the value of a cell as a 32-bit integer, parsed using the invariant culture.
Public methodTryGetInt(String, Int32, Int32)
Retrieves the value of a cell as a 32-bit integer, addressing the column by header name.
Public methodTryGetLong(Int32, Int32, Int64)
Retrieves the value of a cell as a 64-bit integer, parsed using the invariant culture.
Public methodTryGetLong(String, Int32, Int64)
Retrieves the value of a cell as a 64-bit integer, addressing the column by header name.
Public methodTryGetPoint
Retrieves a row as a 3-D point. This succeeds only when ColumnCount is 3: the row's three fields are joined and passed to TryParse(String, Point3d).
Public methodTryGetString(Int32, Int32, String)
Retrieves the value of a cell as a string.
Public methodTryGetString(String, Int32, String)
Retrieves the value of a cell as a string, addressing the column by header name.
Top
See Also