Olecontainer Operate Excel to read and write databases in binary mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.