TdxSpreadSheet creation and filling via code

Basic usage and formatting

procedure TForm1.b1Click(Sender: TObject);
Var xls:TdxSpreadSheet;
    sh: TdxSpreadSheetTableView;
begin
  xls:=TdxSpreadSheet.Create(Self);
  Try
    xls.BeginUpdate;
    xls.ClearAll;
    sh:=TdxSpreadSheetTableView(xls.AddSheet('Bénéficiaires'));

    // row,col
    if Cells[1,1]=Nil then
      CreateCell(1,1);
    Cells[Row,Col].AsString:='test';
    sh.cells[1,1].Style.Borders[bLeft].Style:=sscbsDouble;
    sh.cells[1,1].Style.Borders[bRight].Color:=clred;
    sh.Cells[1,1].Style.Brush.BackgroundColor:=clcxLightGray;
    sh.Cells[1,1].Style.AlignHorz:=ssahCenter;
    sh.Cells[1,1].Style.DataFormat.FormatCode:='dd/mm/yyyy';
    sh.Cells[1,1].Style.DataFormat.FormatCode:='# ##0.00';
    sh.Cells[1,1].Style.Font.Style:=[fsBold];

    // Formula
    CreateCell(2,1); // B3
    sh.Cells[2,1].SetText('=SUM(B2:B2)',true);

    xls.EndUpdate;
    xls.SaveToFile('C:\Users\gosane\Desktop\text.xlsx');
  Finally
    xls.Free;
  End;
end;

Helpers

function xlscolname(i:integer):string;
var a,b:integer;
begin
  if i<0 then
    result:='?'
  else if i<26 then
    result:=chr(65+i)
  else begin
    a:=i div 26;
    b:=i mod 26;
    result:=chr(64+a)+chr(65+b);
  end;
end;

Working with TPgDAC (DevArt components for Delphi)

TPgLoader

interface uses DALoader,PgLoader;

Type TMyForm = Class(TForm)
       // ...
       private
         procedure PgLoader1PutData(Sender: TDALoader);
     End;

{...}

procedure TFxxx.PgLoader1PutData(Sender: TDALoader);
var i:Integer;
begin
  for i:=1 to 10 do
    Sender.PutColumnData('fieldname',i,Value);
end;


procedure TFxxx.Import;
Var pgl:TPgLoader;
begin
  pgl:=TPgLoader.Create(Application);
  Try
    pgl.Connection:=DM.PgConnection1;
    pgl.TableName:='MyTableName';
    pgl.Options.BufferSize:=65536;
    // pgl.OnProgress:=LoaderProgress;
    pgl.OnPutData:=PgLoader1PutData;
    pgl.CreateColumns;
    // Remove primary key from PgLoader
    for I := 0 to pgl.Columns.Count-1 do
      if pgl.Columns[i].Name='idprimarykey' then begin
        pgl.Columns.Delete(i);
        break;
      end;
    pgl.Load;
  Finally
    pgl.Free;
  End;
end;