Solved

Delphi/Excel connection problems

Posted on 2007-11-17
2
420 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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now