Board index » delphi » Connecting to excel file using ADO....don't work

Connecting to excel file using ADO....don't work

Before I used Delhi5 with Office97 ...

Now i'm using delhi6 and office2000 on windows2000

If I do the same as i did before...or uses the same file that used to work..it wont work

The testfile was found here:
http://community.borland.com/article/0,1410,20066,00.html

I'm doing exactly the same as they write.
But still I recieve the error message: Cant find the result table.  or any table that i test (other excel files)
First...it complains when I leave the $ after the table name (generated by Delhi itself)..and after removing the $sign...then it cant find it
when i press active.(the error message above)

Why is it so hard to connect to a stupid excel file?
How should I do to make it work.?

I really need it to work.

Ive got another program that exports data only to excel....and i just want to be able to read the file and extract the data to my delphi
program so that I can work with it.

Pleaseeeeeee help me.

 

Re:Connecting to excel file using ADO....don't work


Use brackets:

procedure TForm1.Button1Click(Sender: TObject);
var
 conn: TADOConnection;
 ds: TADODataSet;
begin
 conn := TADOConnection.Create(Self);
 ds := TADODataSet.Create(Self);

 conn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
  'Data Source=C:\My Documents\test.xls;Extended Properties=Excel 8.0;';
 conn.Connected := True;

 ds.Connection := conn;
 ds.CommandText := 'Select * from [Sheet1$]';

//This will work too, but only with brackets
// ds.CommandType := cmdTable;
// ds.CommandText := '[Sheet1$]';

 ds.Active := True;

 ds.First;
 while not ds.Eof do begin
    //Do what you need here
  ds.Next;
   end;

 ds.Active := False;
 conn.Connected := False;

 ds.Free;
 conn.Free;
end;

In IDE you could use TADOTable and it works.

Regards,
Vassiliev V.V.,
http://www.oledbdirect.com

"Tony Turujlija" <Ton...@home.se> ???????/???????? ? ???????? ?????????:
news:1103_1011598783@newsgroups.borland.com...

Quote
> Before I used Delhi5 with Office97 ...

> Now i'm using delhi6 and office2000 on windows2000

> If I do the same as i did before...or uses the same file that used to
work..it wont work

> The testfile was found here:
> http://community.borland.com/article/0,1410,20066,00.html

> I'm doing exactly the same as they write.
> But still I recieve the error message: Cant find the result table.  or any

table that i test (other excel files)
Quote
> First...it complains when I leave the $ after the table name (generated by

Delhi itself)..and after removing the $sign...then it cant find it
Quote
> when i press active.(the error message above)

> Why is it so hard to connect to a stupid excel file?
> How should I do to make it work.?

> I really need it to work.

> Ive got another program that exports data only to excel....and i just

want to be able to read the file and extract the data to my delphi
Quote
> program so that I can work with it.

> Pleaseeeeeee help me.

Other Threads