Introduction
EasyCSV
is a Free Pascal unit for reading an writing CSV files
(Comma Separated Values). It aims at an easy, line based API.
Author
Frank Fischer frank-fischer@shadow-soft.de
License
Download
Latest release: easycsv-0.8.1.tar.gz
Latext development version: easycsv-trunk.tar.gz
Build
There are several ways to use EasyCSV
.
- Download the file
easycsv.pas
and put it in your source directory. - Download the sources and run
fppkg install
in the root directory of the source. This will installEasyCSV
as a Free Pascal package.
Usage
Using the unit in your program
uses easycsv;
Reading a CSV file
Reading a CSV file is done with the class TCSVReader
:
program ReadCSV;
uses easycsv;
var
csv : TCSVReader;
row : TCSVReader.TRow;
i : Integer;
begin
{ Just show the csv file }
csv := TCSVReader.Create('your-file.csv');
for row in csv do begin
for i := 0 to row.Count - 1 do begin
if i > 0 then write(' ');
write(row[i]);
end;
writeln;
end;
csv.Free;
end.
See the API-documentation for a more detailed overview of TCSVReader
.
Writing a CSV file
Writing a CSV file is done with the class TCSVWriter
:
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.
See the API-documentation for a more detailed overview of TCSVWriter
.
Documentation
The homepage of the project is at https://chiselapp.com/user/fifr/repository/pas-easycsv.
All classes of EasyCSV
are documented in the API Documentation