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

Overview

Methods

Public constructor Create; reintroduce;
Public constructor Create(stream : TStream);
Public constructor Create(filename : String);
Public destructor Destroy; override;
Public procedure AddRow(elems : array of String);
Public procedure AddRow(elems : array of const);
Public procedure AddCells(elems : array of const);
Public procedure AddCells(elems : array of String);
Public procedure AddCell(elem : String);
Public procedure EndRow;

Properties

Public property Output : TStream write SetOutput;
Public property OutputFile : String write SetOutputFile;
Public property Delimiter : char read Fdelimiter write Fdelimiter;
Public property QuoteChar : char read FquoteChar write FquoteChar;
Public property LineEnding : char read FlineEnding write FlineEnding;
Public property OwnsStream : Boolean read FownsStream write FownsStream;

Description

Methods

Public constructor Create; reintroduce;

Create a new uninitialized CSV writer.

Public constructor Create(stream : TStream);

Create a CSV writer writing to the given stream.

Public constructor Create(filename : String);

Create a CSV writer writing to the given named file.

Public destructor Destroy; override;
 
Public procedure AddRow(elems : array of String);

Add a complete row of string cells.

A line ending is added after the last cell.

Public procedure AddRow(elems : array of const);

Add a complete row of typed cells.

A line ending is added after the last cell.

Public procedure AddCells(elems : array of const);

Add one or more cells to the current row

Public procedure AddCells(elems : array of String);

Add one or more cells to the current row

Public procedure AddCell(elem : String);

Add one cells to the current row

Public 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

Public property Output : TStream write SetOutput;

Set the output stream

Public property OutputFile : String write SetOutputFile;

Set the output to the given named file

Public property Delimiter : char read Fdelimiter write Fdelimiter;

The separator between cells in a row (default: DefaultDelimiter)

Public property QuoteChar : char read FquoteChar write FquoteChar;

The quote character (default: DefaultQuoteChar)

Public property LineEnding : char read FlineEnding write FlineEnding;

The row separator (default: DefaultLineEnding)

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