Solved

Delphi/Excel connection problems

Posted on 2007-11-17
2
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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