Demand Source:
Olecontainer is used to operate on Excel. To save the Excel file to the database in binary format and read it in binary format
Stream storage:
Procedure savetostream (adotable1: tadotable)
VaR
Vstream: tmemorystream;
Begin
Try
Try
Vstream: = tmemorystream. Create;
Vstream. Clear;
Olecontainer1.savetostream (vstream );
Vstream. Position: = 0;
Adotable1.append;
Tblobfield (adotable1.fieldbyname ("blobfield"). loadfromstream (vstream );
Adotable1.post;
Finally
Freeandnil (vstream );
End;
Except
Exit;
End;
End;
Read stream:
Procedure loadfromstream (adotable1: tadotable)
VaR
// Note: tadoblobstream is used here. If tmemorystream and other stream classes are used, an error will occur.
// The binary stream format of olecontainer is different from that of access.
// Tadoblobstream is used to convert access streams. tadoblobstream inherits from tmemorystream.
Vstream: tadoblobstream;
Begin
Try
Vstream: = tadoblobstream. Create (tblobfield (adotable1.fieldbyname ("blobfield"), bmread );
If (olecontainer1.state = osopen) or (olecontainer1.state = osuiactive) then
Begin
Olecontainer1.destroyobject;
End;
Vstream. Position: = 0;
Olecontainer1.loadfromstream (vstream );
Except
End;
End;
Summary:
Pay attention to the stream format.
Note: There is a small tool in the attachment to help you read excel in access. Http://www.delphibbs.com/keylife/iblog_show.asp? Xid = 21941