Hi, I am using excel 2003 Active Perl 5.8.8 Build 817 and cannot get the UsedRange syntax (as Per Perl Monks tips example) to work. When I use Strict I fail with a run time compile error for xlprevious. When I don't use Strict I get a type mismatch error on SearchDirection. When I initially installed the OLE module I also got a version control issue and had to change the OLE.PM hard coded version from 1704 to 1403.
I can confirm that excel is installed as I can perform other excel functions ... it mainly seems related to the xlnnnnn type parameters. I previously had success with this code with different version of excel and active state perl 5.6.
Please Help.
This is the essence of my code
#!C:/Perl/bin/perl use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use Win32::OLE qw(in valof with); use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... my $DateFormat = "DDD mmm dd, yyyy -- hh:mm:ss"; # Directory to store uploaded customer files my $uploadc_dir = "E:/Inetpub/wwwroot/someplace/somefilelib"; my $query = new CGI; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{DisplayAlerts}=0; my $IBook = $Excel->Workbooks->Open("E:\\afile"); # select worksheet number 1 (you can also select a worksheet by name) +and activate it my $ISheet = $IBook->Worksheets(1); $ISheet->Activate(); # Find last row and last column my $LastRow = $ISheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; my $LastCol = $ISheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByColumns})->{Column};
Edited 2 Apr 2006 (~21:30 PDT) by footpad: Added rudimentary formatting tags.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |