Board index » delphi » How can I easily save queried data into a file or print them out

How can I easily save queried data into a file or print them out

I used OracleDatset to handle data query and used DBGrid to display
queried data.  If I do not want to make a quick report to display them
again, how can I easily save queried data into a disk file or print them
out directly.

Thanks in advance for your help.

Menghua Wang

 

Re:How can I easily save queried data into a file or print them out


I used OracleDatset to handle data query and used DBGrid to display
queried data.  If I do not want to make a quick report to display them
again, how can I easily save queried data into a disk file or print them
out directly.

Thanks in advance for your help.

Menghua Wang

Re:How can I easily save queried data into a file or print them out


I have written a component called PrintDBGrid for this purpose - to print
the grid, export it to a file or send it to the clipboard.

You can find a evaluation version at

http://home.sol.no/~oysteinj/delphi/components/printdbgrid

I think this will solve your problems.

Best regards
Oystein

Menghua Wang skrev i meldingen <35A3C1A2.79C5C...@showme.missouri.edu>...

Quote
>I used OracleDatset to handle data query and used DBGrid to display
>queried data.  If I do not want to make a quick report to display them
>again, how can I easily save queried data into a disk file or print them
>out directly.

>Thanks in advance for your help.

>Menghua Wang

Re:How can I easily save queried data into a file or print them out


On Wed, 08 Jul 1998 13:59:46 -0500, Menghua Wang

Quote
<mw...@showme.missouri.edu> wrote:
> I used OracleDatset to handle data query and used DBGrid to display
> queried data.  If I do not want to make a quick report to display them
> again, how can I easily save queried data into a disk file or print them
> out directly.

Try something like this, for a .CSV-file (Comma-Separated Values):

|procedure SaveDataCSV(DataSet: TDataSet;  FileName: TCaption);
|var Counter: Integer;  TextFile: System.Text;
|begin
|
|  AssignFile(TextFile, FileName);
|  Rewrite(TextFile);
|
|  if not DataSet.Active then DataSet.Open;
|  DataSet.First;
|  while not DataSet.EOF do begin
|
|    Write(TextFile, '"');
|
|    for Counter := 0 to DataSet.FieldCount - 2 do
|      Write(TextFile, DataSet.Fields[Counter].AsString,'",');
|
|    Write(TextFile, DataSet.Fields[DataSet.FieldCount - 1].AsString);
|    WriteLn(TextFile, '"');
|
|    DataSet.Next;
|
|  end;  { while not DataSet.EOF }
|
|  CloseFile(TextFile);
|
|end;  { procedure SaveDataCSV }

It's rather ugly in that it is hard-coded to use " as a data delimiter
and , as a data separator - the user should really have the option to
set delimiter and separator for himself (in the Control Panel Regional
Settings, International on older systems). " and , aren't the default
in many countries - where I live, for example, , is a standard decimal
separator, we use ; for lists. I thought there were "magic" variables,
like ShortDateFormat and all that, which Delphi automatically fetches
from the Control Panel on start-up, but I can't find them anywhere...?

For printing it's the same, except that you replace the text file with
Printer.Canvas, the file-writing functions with Canvas.TextOut(?), and
my file setup and shutdown with Printer setup and shutdown procedures,
whatever they might be. But it is still the same *principle*. I think.

(Maybe, just maybe, you might even be able to use this to write to the
printer - does anybody know if one can still use LPT1 as a file name?)

HTH!

        Christian R. Conrad
--
Proud and sole owner of all opinions (except quotes) expressed above!
======================================================================
            I work at Hedengren, in Finland. Country codes
           are two letters, e-mail addresses are lowercase.
======================================================================
     "Wave goodbye to RISC. It's the rotary engine of computing."
            Brad Aisa, in comp.lang.pascal.delphi.advocacy

Other Threads