给你一段代码参考一下吧,主要用到 Stream 操作,如下:
读 word 文档:
procedure TfmBlob.btnReadDocClick(Sender: TObject);
var
BStream: TBlobStream;
FStream: TFileStream;
begin
BStream := TBlobStream.Create(Table1Doc,bmRead);
FStream := TFileStream.Create('C:/' + Edit1.Text,fmCreate); //用edit 指定文件名
FStream.CopyFrom(BStream,BStream.Size);
BStream.Free;
FStream.Free;
OleContainer1.CreateObjectFromFile('C:/' + Edit1.Text,false)
end;
写 word 文件到 字段里:
procedure TfmBlob.btnSaveClick(Sender: TObject);
var
FStream: TFileStream;
BStream: TBlobStream;
begin
if not OpenDialog1.Execute then exit;
FStream := TFileStream.Create(OpenDialog1.FileName,fmOpenRead); //文件流
Table1.Edit;
BStream := TBlobStream.Create(Table1Doc,bmReadwrite);
with BStream do begin
Seek(0,soFromBeginning); //截断原来的流
Truncate;
CopyFrom(FStream,FStream.Size)
end;
Table1.Post;
BStream.Free;
FStream.Free;
end;