Solved

Delphi/Excel connection problems

Posted on 2007-11-17
2
427 Views
Last Modified: 2010-04-05
I am connecting through ADO Connection and Query to Excel workbook. I have two problems.


1/ The Excel workbook comes to me with spaces in the column titles. Within Delphi is it possible to delete the spaces or change the column names?

2/Having changed the Excel column names manually, I am able to connect and sort the workbook sheets. The workbook appears in a connected DBGrid. However, when I run the following code adoquery1.first; X:=adoquery1['fieldname'].Asstring; label1.caption:=x; I get the following error "Variant does not reference an automation Object' So I need solutions to these two problems, please.
0
Comment
Question by:nicholasjfox
2 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 50 total points
ID: 20306391
var columnname: string;
columnname := Trim(columnname);  // will remove spaces before and after

X:=adoquery1['fieldname'].Asstring  << error, use either
X:=adoquery1['fieldname']  or   X:=adoquery1.FieldByName('fieldname').AsString
the square brackets return a Variant right away, so no need for AsString.
0
 

Author Comment

by:nicholasjfox
ID: 20306962
Sorry I should have said the spaces in the column names are in the middle, ie "Test Results". I can't seem to do anything with the table unless I manually delete the spaces to make
"testresults".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now