🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1865

Re: ADO and Excel

#1865
From: Viatcheslav V. Vassiliev
Date: Sun, 25 Jan 2004 14:40
110 lines
4870 bytes
You can not access to cells with their names with ADO (i.e. A1, C5 etc.).
You will get a table with column names that are taken from the first row or
are auto-generated. You should add data to the excel file if you want to see
them in ADO.

BTW, when you connect to excel file, it is created if it does not exists.

After connecting to excel file, try to execute (call ADOConnection::Execute
for every line)

CREATE TABLE [MySheet] (Col1 Int, Col2 VarChar(20))
INSERT INTO [MySheet] Values (1, 'Row1')
INSERT INTO [MySheet] Values (2, 'Row2')

This should create sheet MySheet and named diapason MySheet for whole sheet.
Then set TableName for TADOTable at MySheet and set its active property to
true. See result in attached DBGrid.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi + ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Lee" <golee@charter.net> �������/�������� � �������� ���������:
news:4013b534$1@newsgroups.borland.com...
> Viatcheslav,
>
> Thank you for your responce, although I am not really sure that I
understand
> it.
>
> Here is what I have:
> //Creates the excel file
> String CB1 = ComboBox2->Text.SetLength(ComboBox2->Text.Length() -4);
> String reportName = CB1 +"_"+ ComboBox3->Text+ ".xls";
>
> Variant XL;
> XL= CreateOleObject("Excel.Application");
> XL.OlePropertySet("Visible",false);
> XL.OlePropertySet("DisplayAlerts",false);
> XL.OlePropertyGet("Workbooks").OleProcedure("Add");
> //Delets the file if it exists
> if (FileExists(GetCurrentDir()+"\\"+reportName))
>     {
>     DeleteFile(GetCurrentDir()+"\\"+reportName);
>     }
> //save the new file
> XL.OleProcedure("Save",GetCurrentDir()+"\\"+reportName);
> XL.OleFunction("Quit");
>
> Data->ExcelTable->ConnectionString =
>     "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+reportName+";"
>     "Extended Properties=Excel 8.0;Persist Security Info=False";
> Data->ExcelTable->Fields->Fields['A1']->AsString = "Hello";
>
> I am getting an EListError with message "list index out of bounds" error
> now. I have the sheet name typed in to the properties of the ADO table
> component as Sheet1$
>
> Thank you for your help
>
> Lee
>
>
>
>
> "Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
> news:401265f9$1@newsgroups.borland.com...
> > Create ADO connection with connection string:
> >
> > Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\MyFile.xls;Extended
> > properties=Excel 8.0
> >
> > Excel 5.0 for MS Excel 5/95 speadsheet
> >
> > Create TADODataSet, TADOTable or TADOQuery and connect to speadsheet.
> Table
> > name is [DiapasonName] for named diapason, [$Sheet1] for sheet,
> > [Sheet1$B5:C10] for cell range.
> >
> > Work with TADODataSet (TADOTable, TADOQuery) as usual. If you do not
want
> > SQL even if it is hidden from you use server-side cursor (client-side
> cursor
> > will create and execute SQL commands internally).
> >
> > //------------------------------------------
> > Regards,
> > Vassiliev V. V.
> > http://www.managed-vcl.com - using .Net objects in Delphi + ADO.Net
> > http://www.oledbdirect.com - The fastest way to access MS SQL Server,
> > MS Jet (Access) and Interbase (through OLEDB)
> >
> > "Lee" <golee@charter.net> �������/�������� � �������� ���������:
> > news:4012423b$1@newsgroups.borland.com...
> > > Does any one know if I can post information into an excel spread sheet
> > with
> > > out using SQL, but using straight ADO connection.  I am using BCB5 Ent
> > and
> > > if it can be done, could I get a code sample?  Thanks
> > >
> > > Thanks
> > >
> > >
> >
> >
>
>
Technical Details
Message-ID: <4013d928$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4012423b$1@newsgroups.borland.com> <401265f9$1@newsgroups.borland.com> <4013b534$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,84d0342e6b56816d
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2004-01-25 07:09:34 PST
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <4012423b$1@newsgroups.borland.com> <401265f9$1@newsgroups.borland.com> <4013b534$1@newsgroups.borland.com>
Subject: Re: ADO and Excel
Date: Sun, 25 Jan 2004 17:40:03 +0300
Lines: 112
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 213.234.218.42
Message-ID: <4013d928$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1075042600 213.234.218.42 (25 Jan 2004 06:56:40 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail