Jump to content

Recommended Posts

Posted
uses JvDBGridExport, DBGrids;  // Activex; for Word/Excel

var
   mygrid : TDBGrid;
   myexport : TJvDBGridCSVExport;
    //   myexport : TJvDBGridExcelExport;
    //   myexport : TJvDBGridWordExport;
    //   myexport : TJvDBGridHTMLExport;

begin
      mygrid := TDBGrid.Create(nil);
      mygrid.DataSource := unimainmodule.myexportdatasource;
      //     CoInitialize(nil);   // call only if export to Word/Excel
      myexport := TJvDBGridCSVExport.Create(nil);
      //     myexport := TJvDBGridExcelExport.Create(nil);
      //     myexport := TJvDBGridWordExport.Create(nil);
      //     myexport := TJvDBGridHTMLExport.Create(nil);

      myexport.FileName := 'c:\myexport.csv';
      myexport.ExportSeparator := esSemiColon; // estab, esComma, esSemiColon
      myexport.Grid := mygrid;
      myexport.ExportGrid;
      // read exceptions in: myexport.LastExceptionMessage;

     myexport.Free;
     mygrid.Free;
end;

If you want to export to Word/Excel, then you have to have Office installed on the Server. 

Excel can easily read CSV files.

You need to have JVCL in your Delphi.

  • Like 1
Posted

If using Word/Excel export use:

CoInitialize(nil);
try
  CoInitialize(nil);
  try
    //Do some ADO work
  finally
    CoUninitialize;
  end;
finally
  CoUninitialize;
end;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...