Solved

Delphi/Excel connection problems

Posted on 2007-11-17
2
442 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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