word文件传入和传出数据库

 uses IdGlobal;

    procedure TdjhyForm.SpeedButton2Click(Sender: TObject);

    var

    sfilename:string;

    function BlobContentTostring(const Filename:string):string;

    begin

      with Tfilestream.Create(filename,fmopenread)  do

      try

        setlength(result,size);

        read(pointer(result)^,size);

      finally

        free;

      end;

    end;

    begin

      if opendialog1.Execute then

      begin

        sfilename:=opendialog1.FileName;

        DataModule1.ADOQuery14.Edit;

        DataModule1.ADOQuery14.FieldByName('word').AsString:=blobcontenttostring(sfilename);

        DataModule1.ADOQuery14.Post;

      end;

    end;

    procedure TdjhyForm.SpeedButton1Click(Sender: TObject);

    var

    sfilename:string;

    bs:Tadoblobstream;

    begin

      bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word')),bmread);

      try

        sfilename:=extractfilepath(application.ExeName)+trim(DataModule1.adoquery14.fieldbyname('hybh').AsString);

        sfilename:=sfilename+'.'+'doc';

        bs.SaveToFile(sfilename);

        try

          djhyopenform:=Tdjhyopenform.Create(self);

          djhyopenform.olecontainer1.CreateObjectFromFile(sfilename,false);

          djhyopenform.OleContainer1.Iconic:=true;

          djhyopenform.ShowModal;

        finally

          djhyopenform.Free;

        end;

      finally

        bs.free;

      end;

    end;

转载于:https://www.cnblogs.com/28088191/archive/2008/06/14/1221966.html

你可能感兴趣的:(word文件传入和传出数据库)