Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 28 Mar 2024, 08:25

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 27 May 2023, 07:54 
Offline

Joined: 31 Aug 2018, 19:06
Posts: 92
Hi, please guide me


Top
 Profile  
 
PostPosted: 02 Jun 2023, 19:54 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello

I can suggest two ways.

1. First way. Create a temporary grid for export.

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  Grid: TDBGridEh;
  DS: TDataSource;
  Path: String;
begin
  GetDir(0, Path);
  Path := Path + '\TestXlsFile.xlsx';

  Grid := TDBGridEh.Create(nil);
  DS := TDataSource.Create(nil);
  Grid.DataSource := DS;
  DS.DataSet := MemTableEh1;
  ExportDBGridEhToXlsx(Grid, Path, nil);
  DS.Free;
  Grid.Free;

  ShellExecute(Application.Handle, 'Open', PChar(Path), nil, nil, SW_SHOWNORMAL)
end;


2. The second way. Use the TXlsMemFileEh class.

Code:
procedure TForm1.Button2Click(Sender: TObject);
var
  xlsFile: TXlsMemFileEh;
  Path: String;
  Sheet: TXlsWorksheetEh;
  i, ci: Integer;
begin
  GetDir(0, Path);
  Path := Path + '\TestXlsFile.xlsx';
  xlsFile := TXlsMemFileEh.Create;

  Sheet := xlsFile.Workbook.Worksheets[0];

  //Export Data rows
  i := 0;
  MemTableEh1.DisableControls;
  MemTableEh1.First;
  while not MemTableEh1.Eof do
  begin
    for ci := 0 to MemTableEh1.FieldCount - 1 do
    begin
      Sheet.Cells[ci, i].Value := MemTableEh1.Fields[ci].Value;
    end;

    i := i + 1;
    MemTableEh1.Next;
  end;
  MemTableEh1.First;
  MemTableEh1.EnableControls;

  xlsFile.SaveToFile(Path);
  xlsFile.Free;

  ShellExecute(Application.Handle, 'Open', PChar(Path), nil, nil, SW_SHOWNORMAL)
end;

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 52 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group