Board index » delphi » How to send data in a paradox(*.db) file to an excel file

How to send data in a paradox(*.db) file to an excel file

Hi,

Can anyone tell me how I can send the data in a paradox (*.db) file to
an excel file.
I use a query to select all from the paradox file.

Regards,
Ricky.........

 

Re:How to send data in a paradox(*.db) file to an excel file


Hi Ricky,
heres an example of some code i use to do a similar thing. I dont believe it
creates a native excel file but it seems to work fine for me. Im simply
using a DBgrid which displays the data before saving. you could probably
modify it to just use a dataset.

CopyFullDBGridToFile(DBGrid1,#9,True,FilePathName);

procedure TDataViewForm.CopyFullDBGridToFile(aCustomGrid: TCustomGrid;
                                    sSeperator: String;
                                    bIncludeHeaders: Boolean;
                                    SaveFilePath : String);
{---------------------------------------------------------------------------
---}
{ Copies the all rows in the grids to the File,  including column headers.
  Columns are seperated by the sSeperator string,  which, for things like
Excel,
  should be set to #9 (Tab).  If the include headers option is chosen the
column
  names are place in the first row }
var
  m: TMemoryStream;
  j: Integer;
  S: String;
  aBookMark: TBookMark;
  aDataSet: TDataSet;
begin
  m := TMemoryStream.Create;
  try
    with aCustomGrid do
    begin
      if (aCustomGrid is TDBGrid) then
        aDataSet := (aCustomGrid as TDBGrid).datasource.dataset
      else
        if (aCustomGrid is TDBGrid) then
          aDataSet := (aCustomGrid as TDBGrid).datasource.dataset
        else
          raise Exception.Create('Grid must be TDBGrid or TDBGrid');

      aDataset.DisableControls;
      aBookMark := aDataset.GetBookMark;
      aDataset.first;

      for j := 0 To aDataset.FieldCount - 1 do
      begin
        if aDataset.fields[j].visible then
          S := aDataset.fields[j].FieldName;

        if j = aDataSet.FieldCount - 1  Then
        begin
          AppendStr(S, #13#10);
          m.WriteBuffer( S[1], Length(S));
        end
        else
          if aDataset.fields[j].visible then
          begin
            AppendStr(S, sSeperator);
            m.WriteBuffer( S[1], Length(S));
          end;
      end;

      while not aDataset.EOF do
      begin
        for j := 0 To aDataset.FieldCount - 1 do
        begin
          if aDataset.fields[j].visible then
            S := aDataset.fields[j].asString;

          if j = aDataSet.FieldCount - 1  then
          begin
            AppendStr(S, #13#10);
            m.WriteBuffer( S[1], Length(S));
          end
          else
            if aDataset.fields[j].visible then
            begin
              AppendStr(S, sSeperator);
              m.WriteBuffer( S[1], Length(S));
            end;
        end;
        aDataset.next;
      end;
      aDataset.GotoBookMark(aBookMark);
      aDataset.FreeBookMark(aBookMark);
      aDataset.EnableControls;
    end;
    S[1] := #0;
    m.WriteBuffer( S[1], 1 );
    m.SaveToFile(SaveFilePath);
  finally
    m.Free;
  end;
end;

Hope it helps.
Stuart

Quote
"Ricky Manohar" <r...@ttemail.com> wrote in message

news:3C6D1A1E.BB7E92C4@ttemail.com...
Quote
> Hi,

> Can anyone tell me how I can send the data in a paradox (*.db) file to
> an excel file.
> I use a query to select all from the paradox file.

> Regards,
> Ricky.........

Other Threads