Re: How to copy the content of TDBGrid into Excel file

"fatih olcer" <[email protected]> Wed, 13 Aug 2003 17:29:41 +0300
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <00ac01c361a7$569f0280$c500000a@bmcntdom>
hi,

look at the main code  at:
http://www.swissdelphicenter.ch/en/showcode.php?id=725

//dbtoXLS :

PROCEDURE dbtoXLS(DATA:TDATASET);
VAR BOOKm:POINTER;
    i:integer;    FileN:String;    HH :HWND;
 BEGIN
   IF NOT DATA.ACTIVE THEN EXIT;
   FileN:='c:\dbtoXLS.xls'; // strtoint(high())
   BOOKm:=DATA.GetBookmark;
   DATA.DisableControls;
   DATA.FIRST;
   FStream := TFileStream.Create(FileN, fmCreate);
   TRY
    XlsBeginStream(FStream, 0);
    for i:=0 to Data.FieldCount-1 do
                XlsWriteCellLabel(FStream, i, 0 , data.fields[i].FieldName);

    WHILE NOT DATA.Eof DO
    BEGIN
    for i:=0 to Data.fieldcount-1 do
               XlsWriteVal(FStream,i , data.recno , Data.Fields[i]);
      DATA.NEXT;
    END;
      XlsEndStream(FStream);
   FINALLY
     DATA.GotoBookmark(BOOKm);
     DATA.EnableControls;
     FStream.Free;
   END;
    ShellExecute(HH, 'open', pchar(FileN) , nil, nil, 1);
 END;


{look at fieldtypes}
procedure XlsWriteVal(XLsStream:TStream; Const ERow , ECol :word  ;
Field:TField);
var S:String;
    N:Extended;
 Begin
  N:=0;S:='';
  case field.DataType of
        ftUnknown    : S:='UNKNOWN';
        ftString     : S:=Field.asstring;
        ftSmallint   : N:=Field.asfloat;
        ftInteger    : N:=Field.asfloat;
        ftWord       : N:=Field.asfloat;
        ftBoolean    : S:=Field.asstring;
        ftFloat      : N:=Field.asfloat;
        ftCurrency   : N:=Field.asfloat;
        ftBCD        : N:=Field.asfloat;
        ftDate       : N:=Field.AsFloat;
        ftTime       : N:=Field.AsFloat;
        ftDateTime   : N:=Field.AsFloat;
        ftBytes      : S:='BYTES';
        ftVarBytes   : S:='VARBYTES';
        ftAutoInc    : N:=Field.asfloat;
        ftBlob       : S:='BLOB';
        ftMemo       : S:=field.AsString;
        ftGraphic    : S:='GRAPHIC';
        ftFmtMemo    : S:='FMTMEMO';
        ftParadoxOle : S:='PARADOXOLE';
        ftDBaseOle   : S:='DBASEOLE';
        ftTypedBinary: S:='TYPEBIN';
        ftCursor     : S:='CURSOR';
        ftFixedChar  : S:=field.asstring;
        ftWideString : S:=field.asstring;
        ftLargeInt   : N:=Field.asfloat;
        ftADT        : S:='ADT';
        ftArray      : S:='ARRAY';
        ftReference  : S:='REFER';
        ftDataSet    : S:='DATASET';
        ftOraBlob    : S:='ORABBLOB ';
        ftOraClob    : S:='ORACCBLOB ';
        ftVariant    : S:=field.asstring;
        ftInterface  : S:='INTERFACE';
        ftIDispatch  : S:='IDISPATCH';
        ftGuid       : S:='GUID';
       end;

        if N <> 0 then
           XlsWriteCellNumber(XLsStream, ERow, ECol, N)
         else
           XlsWriteCellLabel(XLsStream, ERow, ECol, S);
 end;




----- Original Message -----
From: "vik_ch_sin" <[email protected]>
To: <[email protected]>
Sent: Wednesday, August 13, 2003 2:24 PM
Subject: Re: [Delphi] How to copy the content of TDBGrid into Excel file


> Thanks Richard
>     but I donot wish to use 3rd party component .
> Can u suggest other alternative with Delphi standard Compaonents
>
> Vikash
> --- In [email protected], "Richard Le Mesurier
> (Investec Employee Benefits)" <richard.lemesurier@i...> wrote:
> > There's a handy component on www.axolot.com (I think that's the
> address,
> > else search on "axolot")
> >
> > That's the one I've used before and its way faster than COM, and
> doesn't
> > require Excel to be on target machine.
> >
> > -----Original Message-----
> > From: vik_ch_sin [mailto:vik_ch_sin@y...]
> > Sent: 13 August 2003 12:08
> > To: [email protected]
> > Subject: [Delphi] How to copy the content of TDBGrid into Excel file
> >
> >
> > Hi Friends
> >  Help me out with this one .
> >
> > I want to copy the content of TDBGrid into Excel Sheet .
> > I wrote the following line of code
> >
> > TCustomDataSet.SaveToFile(fileName.XLS)
> >
> > to do the same .
> >
> > But the XLS file generated has unsupported charecters ...
> >
> > What is the Solution to this
> >
> > Thanks in Advance ...
> > eagerly waiting for ur responce
> >
> > Vikash
> >
> >
> >
> > CodeCoffer - new Delphi code protection Tool!
> > http://www.delphicollection.com/public/CodeCoffer.htm
> > ---------------------------------------------------------------
> > Unsubscribe:[email protected]
> > List owner:[email protected]
> > ---------------------------------------------------------------
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> >
> >
> > NOTICE - This message contains privileged and confidential
> > information intended only for the use of the addressee
> > named above. Any review, retransmission, dissemination,
> > copying, disclosure or other use of, or taking of any
> > action in reliance upon, this information by person or
> > entities other than the intended recipient is prohibited.
> > If you have received this message in error, please notify
> > the sender by return email and delete this message.
> > This message should not be copied or used for any purpose
> > other than intended, nor should it be disclosed to any
> > other person. Any views expressed in this message are those
> > of the individual sender, except where the sender specifically
> >  states them to be the view of Investec Group, its
> > subsidiaries or associates. The Investec Group is not
> > liable for the security of information sent by e-mail at
> > your request, nor for the proper and complete transmission
> > of the information contained in the communication nor for
> > any delay in its receipt. Please note that the recipient
> > must scan this e-mail and any attached files for viruses
> > and the like. The Investec Group accepts no liability of
> > whatever nature for any loss, liability, damage or expense
> > resulting directly or indirectly from the access of any files
> > which are attached to this message.
>
>
>
> CodeCoffer - new Delphi code protection Tool!
> http://www.delphicollection.com/public/CodeCoffer.htm
> ---------------------------------------------------------------
> Unsubscribe:[email protected]
> List owner:[email protected]
> ---------------------------------------------------------------
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM
---------------------------------------------------------------------~->

CodeCoffer - new Delphi code protection Tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/