Please enable JavaScript to view this site.

Codolex

The CSV export activity can be used to export a list of entities to a CSV file.

Uses System.Classes.TStringList

Uses System.Classes.TStrings.SaveToFile

 

CSVExport

Activity properties

 

begin

var CSVList := TStringList.Create;

try

   CSVList.Add('ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued');

  for var Entity in ProductsList do

  begin

    var CSVValue: string;

     

     CSVValue := string.Join(',', [Entity.ProductID.Value, Entity.ProductName.Value, Entity.SupplierID.Value, Entity.CategoryID.Value, Entity.QuantityPerUnit.Value, Entity.UnitPrice.Value, Entity.UnitsInStock.Value, Entity.UnitsOnOrder.Value, Entity.ReorderLevel.Value, Entity.Discontinued.Value]);

     CSVList.Add(CSVValue);

  end;

   CSVList.SaveToFile(ExportFileName);

finally

   CSVList.Free;

end;

end;

Resulting code

 

The separator value is a ',' by default, but can be changed to other separators like ';'.

 

The associations of entities are not included in the export, only the field for association id is included if there is one

 

Known issue

Exclude fields is not implemented in the current version

 

© by GDK Software