Wednesday, November 18, 2015

Create CSV file using Delphi

 I used textfile variable to write to a file (or create it if it don't exist).

 CSV file? Just make sure that the name at assignfile  command had .csv extension, :)

 Of course we have to format the output to meet the CSV standart; separated by comma.


procedure TForm1.Button1Click(Sender: TObject);
var
    fileku:textfile;
    i,j,n:integer;
begin
  n:=10;
  assignfile(fileku,'data.csv');
  rewrite(fileku);
  writeln(fileku,'tadaa...');
  for i:=1 to n do begin
    for j:=1 to n do begin
      writeln(fileku,i,',',j,',','data',i,j);
    end;
  end;
  closefile(fileku);
end;

.