[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

Connecting to an Excelsheet

I want to read some Cells from an Excelsheet. The code below:

procedure TForm1.OpenExcel;
var     ExcelApp : OLEVariant;
        ExcelWorkbook : OLEVariant;
        ExcelSheet : OLEVariant;
        ExcelRange : OLEVariant;
begin
    ExcelApp := CreateOLEObject ('Excel.Application');
    try
        ExcelApp.Workbooks.Open ('C:\Temp\Temp.xls');
        ExcelWorkbook := ExcelApp.ActiveWorkbook;
        ExcelSheet := ExcelWorkbook.ActiveSheet;
        ExcelRange := ExcelSheet.Range ('A1:A1');
        ShowMessage (ExcelRange.Value);
        ExcelApp.ActiveWorkbook.Close;
    finally
        ExcelApp.Quit;
    end;
end;

The result is that I'am able to open this excelfile, but Range ('A1:A1') gives me the error "member not found". I use Excel2000. Where is the mistake?

Thanks a lot for help.
0
bussoftware
Asked:
bussoftware
1 Solution
 
Phoenix_sCommented:
try changing this...

ExcelRange := ExcelSheet.Range ('A1:A1');
       

to this...

ExcelRange := ExcelSheet.Range['A1:A1'];

I know this works in Delphi 4 using OLEVariants as I just finished beating a small application into submission to do this kinda crap ;)

hope this helps
0
 
rarigoCommented:
Hi bussoftware,

   Search for a unit named ads_excel at http://www.advdelphisys.com/index.html


Tchau,
Reginaldo
0
 
bussoftwareAuthor Commented:
Yes, this helped avoiding desperation. Your proposal also works with D5. I tried the new servers in D5, but got an OLE error when opening an excelfile. I think the way described above is the better.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now