How to access an excel spreadsheet through Delphi 5

Posted on 2011-09-28
Last Modified: 2012-05-12
My problem seems to be simple.  I need to open up an odbc driver linked to an excel spreadsheet in Delphi and then read some data from it.  Seems simple, but I can't seem to find the best way.  

First of all I set up a odbc datasource for the spreadsheet.

I then setup a tdatabase component and connected it without a hitch.  I then drop a ttable on the form and reference the tdatabase but when I try to select the tablename the system crashes.  

Using ADO I dropped a tadoconnection on the form, setup the connection string, tested the connection and set the connected to true, no problems.  I then drop a tadotable and referrence the tadoconnection.  There is nothing in the drop down for tablename and when I try to set active = true, it tells me the tablename is missing.

Question by:Randy Rich
  • 2
  • 2
  • 2
  • +1
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 36720470
It's a little bit long to explain how to connect to excel using ado
Here's a tutorial to start in this way
LVL 19

Expert Comment

ID: 36813047
Have you already checked this...

Connecting an Excel Spreadsheet to Delphi using ADO
LVL 19

Expert Comment

ID: 36813056
Another useful link...

Creating a Microsoft Excel Spreadsheet Viewer Using Delphi 5's ADOExpress
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

LVL 25

Expert Comment

ID: 36813246
you may have to setup in excel a region of your spreadsheet that will be the table. that is useful when you have complex speadsheet and want only a specific area of it to be accessible as a table.
I think that is done by selecting the region (with the first line being the column headers), and setting a name to that region. In ribbons GUI, it is in the 'Formula' ribbon, 'Name Manager' section, then 'Define a name'
I know Excel should allow access to each spreadsheet as a whole table, without setting an area name. But maybe there is now security functionality that prevent it to work.
I'll try to test it with an environment as close as possible as yours : what is your Delphi version and what is your Office version ?
LVL 25

Accepted Solution

epasquier earned 500 total points
ID: 36813843
Here is a full sample project, with comments inside the app and the excel file.
Accessing Excel from ADO, while convenient with simple needs, is definitely NO DB alternative, when adding data and joints are required

Author Comment

by:Randy Rich
ID: 36814046
I'm using Delphi 5 and Excel 2010.

Author Closing Comment

by:Randy Rich
ID: 36814339
Wish I could give an A++++.  This was a great solution and the example made it easy to work through!  I know it's not always possible to go to this length to explain something but in this case with all the many variables, it was a tremendous help. Thank you!!!!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 104
tidtcpserver connection lost handle 2 102
update joined tables 2 55
FMX TEdit KeyUp handler detecting  "enter" key 4 13
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question