Class TCSVWriter
Unit
Declaration
type TCSVWriter = class(TObject)
Description
A simple class to write CSV files row by row.
Each row can either be written at once by calling AddRow or it can written cell by cell using AddCells and termined by EndLine.
Example:
program WriteCSV; uses easycsv; var csv : TCSVWriter; i : Integer; begin csv := TCSVWriter.Create('your-file.csv'); // Write a header line csv.AddRow(['Nr', 'Random number']); // Write some random lines for i := 1 to 10 do begin csv.AddRow([i, random(100)]); end; csv.Free; end.
Hierarchy
- TObject
- TCSVWriter
Overview
Methods
constructor Create; reintroduce; |
|
constructor Create(stream : TStream); |
|
constructor Create(filename : String); |
|
destructor Destroy; override; |
|
procedure AddRow(elems : array of String); |
|
procedure AddRow(elems : array of const); |
|
procedure AddCells(elems : array of const); |
|
procedure AddCells(elems : array of String); |
|
procedure AddCell(elem : String); |
|
procedure EndRow; |
Properties
property Output : TStream write SetOutput; |
|
property OutputFile : String write SetOutputFile; |
|
property Delimiter : char read Fdelimiter write Fdelimiter; |
|
property QuoteChar : char read FquoteChar write FquoteChar; |
|
property LineEnding : char read FlineEnding write FlineEnding; |
|
property OwnsStream : Boolean read FownsStream write FownsStream; |
Description
Methods
constructor Create; reintroduce; |
|
Create a new uninitialized CSV writer. |
constructor Create(stream : TStream); |
|
Create a CSV writer writing to the given stream. |
constructor Create(filename : String); |
|
|
destructor Destroy; override; |
|
procedure AddRow(elems : array of String); |
|
Add a complete row of string cells. A line ending is added after the last cell. |
procedure AddRow(elems : array of const); |
|
Add a complete row of typed cells. A line ending is added after the last cell. |
procedure AddCells(elems : array of const); |
|
Add one or more cells to the current row |
procedure AddCells(elems : array of String); |
|
Add one or more cells to the current row |
procedure AddCell(elem : String); |
|
Add one cells to the current row |
procedure EndRow; |
|
End the current row. If this method is called before any cell has been written, nothing happens. In other words, the file cannot start with empty rows. |
Properties
property Output : TStream write SetOutput; |
|
Set the |
property OutputFile : String write SetOutputFile; |
|
Set the output to the given named file |
property Delimiter : char read Fdelimiter write Fdelimiter; |
|
The separator between cells in a row (default: DefaultDelimiter) |
property QuoteChar : char read FquoteChar write FquoteChar; |
|
The quote character (default: DefaultQuoteChar) |
property LineEnding : char read FlineEnding write FlineEnding; |
|
The row separator (default: DefaultLineEnding) |
property OwnsStream : Boolean read FownsStream write FownsStream; |
|
Whether the writer owns the output stream. If the stream is owned then it is freed when the writer is deleted. |
Generated by PasDoc 0.15.0.