in reply to OLE, Excel, and PERL

I'd use Win32::OLE as OLE.pm is deprecated but that's not the problem. You must give the full path to the Excel spreadsheet before it will work.

This is not the greatest example (I haven't included any error checking) but it does work.

use strict; use warnings; use Win32::OLE; my $xlfile ='c:\windows\desktop\test\Book1.xls'; my $xl_app = Win32::OLE->new("Excel.Application"); $xl_app->{'Visible'} = 0; my $workbook = $xl_app->Workbooks->Open($xlfile); my $worksheet = $workbook->Worksheets(1); my $cellA1 = $worksheet->Range("A1")->{'Value'}; my $cellB1 = $worksheet->Range("B1")->{'Value'}; print "Cell A1 = $cellA1"; $worksheet->Range("A1")->{'value'} = "01aBcD2"; $cellA1 = $worksheet->Range("A1")->{'Value'}; print "\nCell A1 = $cellA1"; $cellA1 = uc $cellA1; print "\nCell A1 = $cellA1"; $xl_app->ActiveWorkbook->Close(0); $xl_app->Quit();

Replies are listed 'Best First'.
Re: Re: OLE, Excel, and PERL
by Anonymous Monk on Oct 30, 2002 at 18:19 UTC
    Thanks for your help. I created a file C:\tmp\Book1.xls and updated your code and ran the program and got:
    C:\Documents and Settings\dln1\My Documents\White Papers\AANC>perl tes +t.pl Win32::OLE(0.1502) error 0x80070005: "Access is denied" in PROPERTYPUT "Visible" at test.pl line 6 Win32::OLE(0.1502) error 0x80070005: "Access is denied" in METHOD/PROPERTYGET "" at test.pl line 7 Can't call method "Open" on an undefined value at test.pl line 7.
    It appears there is something wrong. I do not understand what or how to diagnose. Any ideas?

      Do you have Microsoft Excel installed on that computer?